QEventDispatcherWin32::processEvents Logical issues - qt

When see the qt source code(QEventDispatcherWin32::processEvents),i find a Logical issues.code as below,first it writes if(!haveMessage) next if(haveMessage),so code else if (...) and else{...} will never execute,what i think is right?
code as:
if (!haveMessage) {
// no message - check for signalled objects
for (int i = 0; i < (int)nCount; i++)
pHandles[i] = d->winEventNotifierList.at(i)->handle();
waitRet = MsgWaitForMultipleObjectsEx(nCount, pHandles, 0, QS_ALLINPUT, MWMO_ALERTABLE);
if ((haveMessage = (waitRet == WAIT_OBJECT_0 + nCount))) {
// a new message has arrived, process it
continue;
}
}
if (haveMessage) {
#ifdef Q_OS_WINCE
// WinCE doesn't support hooks at all, so we have to call this by hand :(
(void) qt_GetMessageHook(0, PM_REMOVE, (LPARAM)&msg);
#endif
if (d->internalHwnd == msg.hwnd && msg.message == WM_QT_SENDPOSTEDEVENTS) {
if (seenWM_QT_SENDPOSTEDEVENTS) {
// when calling processEvents() "manually", we only want to send posted
// events once
needWM_QT_SENDPOSTEDEVENTS = true;
continue;
}
seenWM_QT_SENDPOSTEDEVENTS = true;
}
else if (msg.message == WM_TIMER) {
// avoid live-lock by keeping track of the timers we've already sent
bool found = false;
for (int i = 0; !found && i < processedTimers.count(); ++i) {
const MSG processed = processedTimers.constData()[i];
found = (processed.wParam == msg.wParam && processed.hwnd == msg.hwnd && processed.lParam == msg.lParam);
}
if (found)
continue;
processedTimers.append(msg);
}
else if (msg.message == WM_QUIT) {
if (QCoreApplication::instance())
QCoreApplication::instance()->quit();
return false;
}
if (!filterEvent(&msg)) {
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
else if (waitRet >= WAIT_OBJECT_0 && waitRet < WAIT_OBJECT_0 + nCount) {
d->activateEventNotifier(d->winEventNotifierList.at(waitRet - WAIT_OBJECT_0));
}
else {
// nothing todo so break
break;
}

Related

Asp.net Telerik script issue

I have a line of code which comes inside a Telerik.Web.UI.Webresource.axd file which breaks something in my custom code.
dataBind:function(){if(this._virtualization&&!this._virtualization._isDataBinding&&((this.get_allowPaging()&&this._dataSource.length>this.get_pageSize())||(!this.get_allowPaging()&&this._dataSource.length>this._virtualization._itemsPerView))){this._virtualization._startIndex=null;
this._virtualization.set_bindingType("Client");
this._virtualization.set_cachedData(this._dataSource);
this._virtualization.set_virtualItemCount(this._dataSource.length);
this._virtualization.select();
return;
}
**Array.forEach($telerik.getElementsByClassName(this.get_element().tBodies[0],"rgGroupHeader"),function(i){i.parentNode.removeChild(i)**;
});
I would like to know if it is possible to prevent the below line of code to be executed
Array.forEach($telerik.getElementsByClassName(this.get_element().tBodies[0],"rgGroupHeader"),function(i){i.parentNode.removeChild(i)**;
You can override the dataBind method of RadGrid which will allow you to customize it:
<script>
Telerik.Web.UI.GridClientSideBinding.prototype.dataBind = function () {
// Virtualization
if (this._virtualization && !this._virtualization._isDataBinding &&
((this.get_allowPaging() && this._dataSource.length > this.get_pageSize()) ||
(!this.get_allowPaging() && this._dataSource.length > this._virtualization._itemsPerView))) {
this._virtualization._startIndex = null;
this._virtualization.set_bindingType("Client");
this._virtualization.set_cachedData(this._dataSource);
this._virtualization.set_virtualItemCount(this._dataSource.length);
this._virtualization.select();
return;
}
Array.forEach($telerik.getElementsByClassName(this.get_element().tBodies[0], "rgGroupHeader"), function (element) {
element.parentNode.removeChild(element);
});
Array.forEach($telerik.getElementsByClassName(this.get_element().tBodies[0], "rgFooter"), function (element) {
element.parentNode.removeChild(element);
});
var noRecordsItem = $telerik.getElementByClassName(this.get_element(), "rgNoRecords");
if (noRecordsItem) {
if (this._dataSource.length > 0) {
noRecordsItem.style.display = "none";
} else {
noRecordsItem.style.display = "";
this._setPagerVisibility(this._data.PagerAlwaysVisible);
}
}
var dataItems = this.get_dataItems();
var columns = this.get_columns();
var i, l1, l2;
var tableElement = ($telerik.isOpera) ? this.get_element() : this.get_element().tBodies[0];
if (this._dataSource.length < dataItems.length || tableElement.rows.length == 1) {
for (i = 0, l1 = dataItems.length; i < l1; i++) {
dataItems[i].set_visible(false);
dataItems[i].get_element().style.display = "none";
}
this._cacheDataItems();
}
this._dataBind(this._dataSource);
var firstSelection = true;
// When YahooStyleScrolling is used in RadGrid and user
//scrolls down, select multiple rows using shift + down arrow key,
//the selection is not persisted on next page load
if (this._owner._keyboardNavigationProperties) {
firstSelection = this._owner._keyboardNavigationProperties.firstSelection;
}
var owner = $find(this._owner.get_id());
if (owner._getPositionedDataItems) {
owner._getPositionedDataItems(true);
}
if (this._owner._keyboardNavigationProperties) {
this._owner._keyboardNavigationProperties.firstSelection = firstSelection;
}
this._fixRowsClassNames();
this._owner.raise_dataBound(Sys.EventArgs.Empty);
for (i = 0, l2 = columns.length; i < l2; i++) {
var isVisible = false;
if (columns[i].get_element().style.visibility != "hidden" && (columns[i].Display == null || columns[i].Display == true) &&
(columns[i]._data.Display == null || columns[i]._data.Display)) {
isVisible = true;
}
if (!isVisible) {
this.hideColumn(i);
}
}
if (this.get_id() == this._owner._masterClientID) {
var grid = $find(this._owner.get_id());
if (grid._scrolling) {
this._owner._scrolling.setHeaderAndFooterDivsWidth();
grid._scrolling._initializeVirtualScrollPaging(true);
}
}
}
</script>

Show ForbiddenCursor only when mouse is OnItem in QTreeWidget

I am trying to display the Qt::ForbiddenCursor when I move a mouse over an item in a custom QTreeWidget but only when drop position is QAbstractItemView::OnItem.
Here is the code
void XProjectTreeWidget::dragMoveEvent(QDragMoveEvent * event)
{
QTreeWidgetItem* pItem = itemAt(event->pos());
if (pItem == nullptr)
{
return;
}
XTreeItem* dropItem = dynamic_cast<XTreeItem*>(pItem);
if (dropItem == nullptr)
{
return;
}
XTreeItem::DropPosition drop;
if (!getDropPosition(drop))
{
return;
}
auto items = selectedItems();
if (items.count() == 0)
{
return;
}
auto dragItem = (XTreeItem*)items.first();
if (!dragItem->checkMoveItemPossible(dropItem, drop))
{
QGuiApplication::changeOverrideCursor(QCursor(Qt::ForbiddenCursor));
event->setDropAction(Qt::IgnoreAction);
}
else
{
QGuiApplication::changeOverrideCursor(QCursor(Qt::ArrowCursor));
event->setDropAction(Qt::MoveAction);
}
QTreeWidget::dragMoveEvent(event);
}
bool XProjectTreeWidget::getDropPosition(XTreeItem::DropPosition& drop)
{
DropIndicatorPosition dropIndicator = dropIndicatorPosition();
switch (dropIndicator)
{
case QAbstractItemView::AboveItem: drop = XTreeItem::Above; break;
case QAbstractItemView::BelowItem: drop = XTreeItem::Below; break;
case QAbstractItemView::OnItem: drop = XTreeItem::Inside; break;
default: return false;
}
return true;
}
The problem is that the ignore action seems to be applied to all the items with the same type for AboveItem and BelowItem.
dragMoveEvent is called when the DropPosition is OnItem for the items with the same type while hovering the cursor above those items.
How can I show ForbiddenCursor only when mouse is OnItem?
Calling QTreeWidget::dragMoveEvent(event); before changing the cursors fixed the issue. Here is how the fixed code looks now:
void XProjectTreeWidget::dragMoveEvent(QDragMoveEvent * event)
{
// moved this call from the end of the method
QTreeWidget::dragMoveEvent(event);
QTreeWidgetItem* pItem = itemAt(event->pos());
if (pItem == nullptr)
{
return;
}
XTreeItem* dropItem = dynamic_cast<XTreeItem*>(pItem);
if (dropItem == nullptr)
{
return;
}
XTreeItem::DropPosition drop;
if (!getDropPosition(drop))
{
return;
}
auto items = selectedItems();
if (items.count() == 0)
{
return;
}
auto dragItem = (XTreeItem*)items.first();
if (!dragItem->checkMoveItemPossible(dropItem, drop))
{
QGuiApplication::changeOverrideCursor(QCursor(Qt::ForbiddenCursor));
event->setDropAction(Qt::IgnoreAction);
}
else
{
QGuiApplication::changeOverrideCursor(QCursor(Qt::ArrowCursor));
event->setDropAction(Qt::MoveAction);
}
}

Desktop Computer - Detecting type of internet connection

Is there any way to detect if my computer is connected via cable or mobile network to the internet?
I tried to analyze the trace-route output but realized that it would need a very large and up-to-date database to detect the type of network the data packages take.
Have this two different types of network maybe some different attributes that are easily to detect?
You can use the NetworkListManager APIs to find if a network is connected to the internet. The example below does both that and checks to see if the network is free. You can just remove the Cost related code:
HRESULT GetFreeInternetInterface(_Out_ GUID* pInterfaceGuid)
{
bool fCoInitialized = false;
HRESULT hr = CoInitializeEx(NULL, COINIT_MULTITHREADED);
if (SUCCEEDED(hr))
{
fCoInitialized = true;
CComPtr<INetworkListManager> pNetworkListManager;
hr = pNetworkListManager.CoCreateInstance(__uuidof(NetworkListManager));
if (SUCCEEDED(hr))
{
CComPtr<IEnumNetworkConnections> pNetworkConnections;
hr = pNetworkListManager->GetNetworkConnections(&pNetworkConnections);
bool fFound = false;
while (SUCCEEDED(hr))
{
CComPtr<INetworkConnection> pNetworkConnection;
hr = pNetworkConnections->Next(1, &pNetworkConnection, nullptr);
if (hr == S_OK)
{
CComPtr<INetworkConnectionCost> pNetworkConnectionCost;
hr = pNetworkConnection.QueryInterface(&pNetworkConnectionCost);
if (SUCCEEDED(hr))
{
NLM_CONNECTIVITY nlmConnectivity = NLM_CONNECTIVITY_DISCONNECTED;
DWORD dwCost = NLM_CONNECTION_COST_UNKNOWN;
if (SUCCEEDED(pNetworkConnection->GetConnectivity(&nlmConnectivity)) &&
(nlmConnectivity & (NLM_CONNECTIVITY_IPV4_INTERNET | NLM_CONNECTIVITY_IPV6_INTERNET)) != 0 &&
SUCCEEDED(pNetworkConnectionCost->GetCost(&dwCost)) &&
dwCost == NLM_CONNECTION_COST_UNRESTRICTED &&
SUCCEEDED(pNetworkConnection->GetAdapterId(pInterfaceGuid)))
{
fFound = true;
break;
}
}
}
else hr = E_NOINTERFACE;
}
if (SUCCEEDED(hr) && !fFound)
hr = E_NOINTERFACE;
}
}
if (fCoInitialized) CoUninitialize();
return hr;
}
Once you have the interface GUID and IP Helper APIs to get the interface type. Here is some code I had that looks for non-cellular networks. You can take it and modify it to do what you need:
BOOL GetAdapterAddresses(
_Out_ PIP_ADAPTER_ADDRESSES * ppIAA
)
{
*ppIAA = NULL;
DWORD len = 0;
DWORD flags = GAA_FLAG_SKIP_ANYCAST|GAA_FLAG_SKIP_MULTICAST|GAA_FLAG_SKIP_DNS_SERVER;
if (GetAdaptersAddresses(AF_UNSPEC, flags, NULL, NULL, &len) != ERROR_BUFFER_OVERFLOW)
return FALSE;
PIP_ADAPTER_ADDRESSES pIAA = (PIP_ADAPTER_ADDRESSES)LocalAlloc(LPTR, len);
if (pIAA) {
GetAdaptersAddresses(AF_UNSPEC, flags, NULL, pIAA, &len);
*ppIAA = pIAA;
return TRUE;
}
return FALSE;
}
bool IsNonCellularIfType(
_In_ IFTYPE IfType
)
{
return // Ignore Loopback and WWAN
IfType != IF_TYPE_SOFTWARE_LOOPBACK &&
IfType != IF_TYPE_WWANPP &&
IfType != IF_TYPE_WWANPP2;
}
DWORD GetNonCellularIfIndex(
)
{
DWORD IfIndex = (DWORD)(-1);
PIP_ADAPTER_ADDRESSES pIAA;
if (GetAdapterAddresses(&pIAA)) {
PIP_ADAPTER_ADDRESSES pIAAList = pIAA;
while (pIAA) {
// Look for Non-Cellular interface
if (pIAA->OperStatus == IfOperStatusUp &&
IsNonCellularIfType(pIAA->IfType)) {
PIP_ADAPTER_UNICAST_ADDRESS_LH pUnicastAddr = pIAA->FirstUnicastAddress;
// Look through all unicast addresses for valid IPv4 or IPv6 addresses
while (pUnicastAddr) {
LPSOCKADDR pAddr = pUnicastAddr->Address.lpSockaddr;
if (pAddr->sa_family == AF_INET) {
if (!IN4_IS_ADDR_LINKLOCAL(&((SOCKADDR_IN *)pAddr)->sin_addr)) {
IfIndex = pIAA->IfIndex;
break;
}
}
else if (pAddr->sa_family == AF_INET6) {
if (!IN6_IS_ADDR_LINKLOCAL(&((SOCKADDR_IN6 *)pAddr)->sin6_addr)) {
IfIndex = pIAA->IfIndex;
break;
}
}
pUnicastAddr = pUnicastAddr->Next;
}
// No need to keep looking any more?
if (IfIndex != (DWORD)(-1))
break; // while (pIAA)
}
pIAA = pIAA->Next;
}
LocalFree(pIAAList);
}
return IfIndex;
}

ASP.NET - What Characters does Server.HtmlEncode Encode into Named Character Entities

What characters does Server.HtmlEncode encode into named character entities?
So far I have only found < > & and " surely there must be more than this?
This is the code of HtmlEncode, so here you can see how they done it.
public static unsafe void HtmlEncode(string value, TextWriter output)
{
if (value != null)
{
if (output == null)
{
throw new ArgumentNullException("output");
}
int num = IndexOfHtmlEncodingChars(value, 0);
if (num == -1)
{
output.Write(value);
}
else
{
int num2 = value.Length - num;
fixed (char* str = ((char*) value))
{
char* chPtr = str;
char* chPtr2 = chPtr;
while (num-- > 0)
{
chPtr2++;
output.Write(chPtr2[0]);
}
while (num2-- > 0)
{
chPtr2++;
char ch = chPtr2[0];
if (ch <= '>')
{
switch (ch)
{
case '&':
{
output.Write("&");
continue;
}
case '\'':
{
output.Write("'");
continue;
}
case '"':
{
output.Write(""");
continue;
}
case '<':
{
output.Write("<");
continue;
}
case '>':
{
output.Write(">");
continue;
}
}
output.Write(ch);
continue;
}
if ((ch >= '\x00a0') && (ch < 'Ā'))
{
output.Write("&#");
output.Write(ch.ToString(NumberFormatInfo.InvariantInfo));
output.Write(';');
}
else
{
output.Write(ch);
}
}
}
}
}
}
.NET 4 and 4.5 encode single quotes also, which doesn't appear to be in the answer

How we Create Custom Decorator that can apply on file field and radio button selection

if We apply any custom decorator on radio button then it will be display on next line so how
we create such custom decorator that will display inline also same for file
checked=false;
function checkedAll (frm1) {
var aa= document.getElementById('frm1');
if (checked == false)
{
checked = true
}
else
{
checked = false
}
for (var i =0; i < aa.elements.length; i++)
{
aa.elements[i].checked = checked;
}
}
function check()
{
var aa= document.getElementById('frm1');
var flag;
for(var i =0; i < aa.elements.length; i++)
{
if(aa.elements[i].type=='checkbox')
{
if(aa.elements[i].checked && aa.elements[i].id !='checkall')
{
flag = true;
}
else if(!aa.elements[i].checked && aa.elements[i].id !='checkall')
{
flag = false;
break;
}
}
}
if(flag)
{
aa.elements.checkall.checked = true;
}
else
{
aa.elements.checkall.checked = false;
}
}
function notempty()
{
var flag=false;
var all ='';
var aa= document.getElementById('frm1');
for(var i =0; i < aa.elements.length; i++)
{
if(aa.elements[i].type=='checkbox')
{
if(aa.elements.checkall.checked)
{
flag = true;
all = 'd';
break;
}
else
{//alert(aa.elements[i].id);
if(aa.elements[i].checked && aa.elements[i].id !='checkall')
{
flag = true;
all += aa.elements[i].id.replace('check','') + '~';
}
}
}
}
if(!flag)
{
alert("please select a contact to delete..");
return false;
}
if(flag)
{
//alert(all);
document.location.href= '/member/public/index/delete?all='+all;
return false;
}
}
onclick='checkedAll(frm1);'>
escape($data->id);?>"
onclick="check();">
10px;" onclick="return notempty();" value="DELETE" />

Resources