bool AccessControl::isBannedAddress(const boost::asio::ip::address& source) { if (!_enabled) return false; bool banned = false; _packetCounterMutex.lock(); if (_banLifeTime > 0) { boost::posix_time::ptime now(boost::posix_time::microsec_clock::local_time()); std::vector<boost::asio::ip::address> parole; for (std::map<boost::asio::ip::address, boost::posix_time::ptime>::iterator iter = _banned.begin(); iter != _banned.end(); iter++) { boost::posix_time::time_duration timeDiff = now - iter->second; if (timeDiff.total_milliseconds() > _banLifeTime * 1000) parole.push_back(iter->first); } for (std::vector<boost::asio::ip::address>::iterator iter = parole.begin(); iter != parole.end(); iter++) { if (_autoNullRoute) { delNullRoute(*iter); } _banned.erase(*iter); } } if (isWhiteListed(source)) { banned = false; } else { if (_denyAllIncoming) { banned = true; } else { banned = _banned.find(source) != _banned.end(); } if (!banned) { banned = isBlackListed(source); } } _packetCounterMutex.unlock(); if (banned && _autoNullRoute) { addNullRoute(source); } return banned; }
void WindowManager::registerWidget(QWidget *widget) { if (isBlackListed(widget)) { addEventFilter(widget, this); } else if (isDragable(widget)) { addEventFilter(widget, this); } }
static bool childrenUseEvent(GtkWidget *widget, GdkEventButton *event, bool inNoteBook) { // accept, by default bool usable = true; // get children and check GList *children = gtk_container_get_children(GTK_CONTAINER(widget)); for (GList *child = children;child && usable;child = g_list_next(child)) { // cast child to GtkWidget if (GTK_IS_WIDGET(child->data)) { GtkWidget *childWidget = GTK_WIDGET(child->data); GdkWindow *window = nullptr; // check widget state and type if (gtk_widget_get_state(childWidget) == GTK_STATE_PRELIGHT) { // if widget is prelight, we don't need to check where event // happen, any prelight widget indicate we can't do a move usable = false; continue; } window = gtk_widget_get_window(childWidget); if (!(window && gdk_window_is_visible(window))) continue; if (GTK_IS_NOTEBOOK(childWidget)) inNoteBook = true; if(!(event && withinWidget(childWidget, event))) continue; // check special cases for which grab should not be enabled if((isBlackListed(G_OBJECT(childWidget))) || (GTK_IS_NOTEBOOK(widget) && Tab::isLabel(GTK_NOTEBOOK(widget), childWidget)) || (GTK_IS_BUTTON(childWidget) && gtk_widget_get_state(childWidget) != GTK_STATE_INSENSITIVE) || (gtk_widget_get_events(childWidget) & (GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK)) || (GTK_IS_MENU_ITEM(childWidget)) || (GTK_IS_SCROLLED_WINDOW(childWidget) && (!inNoteBook || gtk_widget_is_focus(childWidget)))) { usable = false; } // if child is a container and event has been accepted so far, // also check it, recursively if (usable && GTK_IS_CONTAINER(childWidget)) { usable = childrenUseEvent(childWidget, event, inNoteBook); } } } if (children) { g_list_free(children); } return usable; }
bool WindowManager::mousePressEvent(QObject *object, QEvent *event) { // cast event and check buttons/modifiers QMouseEvent *mouseEvent = static_cast<QMouseEvent*>(event); if (!(Qt::NoModifier==mouseEvent->modifiers() && Qt::LeftButton==mouseEvent->button())) { return false; } // check lock if (isLocked()) { return false; } else { setLocked(true); } // cast to widget QWidget *widget = static_cast<QWidget*>(object); // check if widget can be dragged from current position if (isBlackListed(widget) || !canDrag(widget)) { return false; } // retrieve widget's child at event position QPoint position(mouseEvent->pos()); QWidget *child = widget->childAt(position); if (!canDrag(widget, child, position)) { return false; } // save target and drag point _target = widget; _dragPoint = position; _globalDragPoint = mouseEvent->globalPos(); _dragAboutToStart = true; // send a move event to the current child with same position // if received, it is caught to actually start the drag QPoint localPoint(_dragPoint); if (child) { localPoint = child->mapFrom(widget, localPoint); } else { child = widget; } QMouseEvent localMouseEvent(QEvent::MouseMove, localPoint, Qt::LeftButton, Qt::LeftButton, Qt::NoModifier); qApp->sendEvent(child, &localMouseEvent); // never eat event return false; }
//_____________________________________________________________ void WindowManager::registerWidget( QWidget* widget ) { if( isBlackListed( widget ) ) { /* also install filter for blacklisted widgets to be able to catch the relevant events and prevent the drag to happen */ Utils::addEventFilter(widget, this); } else if( isDragable( widget ) ) { Utils::addEventFilter(widget, this); } }
//_____________________________________________________________ void WindowManager::registerWidget( QWidget* widget ) { if( isBlackListed( widget ) || isDragable( widget ) ) { /* install filter for dragable widgets. also install filter for blacklisted widgets to be able to catch the relevant events and prevent the drag to happen */ widget->removeEventFilter( this ); widget->installEventFilter( this ); } }
QFileInfo ScanFileOrFolder::resolvDestination(const QFileInfo &destination) { QFileInfo newDestination=destination; while(newDestination.isSymLink()) { ULTRACOPIER_DEBUGCONSOLE(Ultracopier::DebugLevel_Notice,QStringLiteral("resolv destination to: %1").arg(newDestination.symLinkTarget())); if(QFileInfo(newDestination.symLinkTarget()).isAbsolute()) newDestination.setFile(newDestination.symLinkTarget()); else newDestination.setFile(newDestination.absolutePath()+text_slash+newDestination.symLinkTarget()); } do { fileErrorAction=FileError_NotSet; if(isBlackListed(destination)) { ULTRACOPIER_DEBUGCONSOLE(Ultracopier::DebugLevel_Warning,QStringLiteral("isBlackListed: %1").arg(destination.absoluteFilePath())); emit errorOnFolder(destination,tr("Blacklisted folder"),ErrorType_Folder); waitOneAction.acquire(); ULTRACOPIER_DEBUGCONSOLE(Ultracopier::DebugLevel_Notice,"actionNum: "+QString::number(fileErrorAction)); } } while(fileErrorAction==FileError_Retry || fileErrorAction==FileError_PutToEndOfTheList); return newDestination; }
bool WindowManager::isDragable(QWidget *widget) { // check widget if (!widget) { return false; } // accepted default types if ((qobject_cast<QDialog*>(widget) && widget->isWindow()) || (qobject_cast<QMainWindow*>(widget) && widget->isWindow()) || qobject_cast<QGroupBox*>(widget)) { return true; } // more accepted types, provided they are not dock widget titles if ((qobject_cast<QMenuBar*>(widget) || qobject_cast<QTabBar*>(widget) || qobject_cast<QStatusBar*>(widget) || isToolBar(widget)) && !isDockWidgetTitle(widget)) { return true; } // flat toolbuttons if (QToolButton *toolButton = qobject_cast<QToolButton*>(widget)) { if (toolButton->autoRaise()) { return true; } } // viewports /* one needs to check that 1/ the widget parent is a scrollarea 2/ it matches its parent viewport 3/ the parent is not blacklisted */ if (QListView *listView = qobject_cast<QListView*>(widget->parentWidget())) { if (listView->viewport() == widget && !isBlackListed(listView)) { return true; } } if (QTreeView *treeView = qobject_cast<QTreeView*>(widget->parentWidget())) { if (treeView->viewport() == widget && !isBlackListed(treeView)) { return true; } } /* catch labels in status bars. this is because of kstatusbar who captures buttonPress/release events */ if (QLabel *label = qobject_cast<QLabel*>(widget)) { if (label->textInteractionFlags().testFlag(Qt::TextSelectableByMouse)) { return false; } QWidget *parent = label->parentWidget(); while (parent) { if (qobject_cast<QStatusBar*>(parent)) { return true; } parent = parent->parentWidget(); } } return false; }