Don't loop indefinitely while trying to teach manners to Qt
[quassel.git] / src / qtui / qtui.cpp
index 2297321..0a2de59 100644 (file)
@@ -40,7 +40,6 @@ QPointer<QtUi> QtUi::_instance = 0;
 QPointer<MainWin> QtUi::_mainWin = 0;
 QList<AbstractNotificationBackend *> QtUi::_notificationBackends;
 QList<AbstractNotificationBackend::Notification> QtUi::_notifications;
-QtUiStyle *QtUi::_style = 0;
 
 QtUi::QtUi() : GraphicalUi() {
   if(_instance != 0) {
@@ -49,13 +48,13 @@ QtUi::QtUi() : GraphicalUi() {
   }
   _instance = this;
 
-  setContextMenuActionProvider(new ContextMenuActionProvider(this));
-  setToolBarActionProvider(new ToolBarActionProvider(this));
-
   QtUiSettings uiSettings;
   Quassel::loadTranslation(uiSettings.value("Locale", QLocale::system()).value<QLocale>());
 
-  _style = new QtUiStyle;
+  setContextMenuActionProvider(new ContextMenuActionProvider(this));
+  setToolBarActionProvider(new ToolBarActionProvider(this));
+
+  setUiStyle(new QtUiStyle(this));
   _mainWin = new MainWin();
 
   setMainWidget(_mainWin);
@@ -67,7 +66,6 @@ QtUi::QtUi() : GraphicalUi() {
 QtUi::~QtUi() {
   unregisterAllNotificationBackends();
   delete _mainWin;
-  delete _style;
 }
 
 void QtUi::init() {
@@ -111,7 +109,7 @@ const QList<AbstractNotificationBackend *> &QtUi::notificationBackends() {
 
 uint QtUi::invokeNotification(BufferId bufId, AbstractNotificationBackend::NotificationType type, const QString &sender, const QString &text) {
   static int notificationId = 0;
-  //notificationId++;
+
   AbstractNotificationBackend::Notification notification(++notificationId, bufId, type, sender, text);
   _notifications.append(notification);
   foreach(AbstractNotificationBackend *backend, _notificationBackends)
@@ -122,11 +120,10 @@ uint QtUi::invokeNotification(BufferId bufId, AbstractNotificationBackend::Notif
 void QtUi::closeNotification(uint notificationId) {
   QList<AbstractNotificationBackend::Notification>::iterator i = _notifications.begin();
   while(i != _notifications.end()) {
-    if((*i).notificationId == notificationId) {
+    if(i->notificationId == notificationId) {
       foreach(AbstractNotificationBackend *backend, _notificationBackends)
         backend->close(notificationId);
       i = _notifications.erase(i);
-      break;
     } else ++i;
   }
 }
@@ -134,9 +131,9 @@ void QtUi::closeNotification(uint notificationId) {
 void QtUi::closeNotifications(BufferId bufferId) {
   QList<AbstractNotificationBackend::Notification>::iterator i = _notifications.begin();
   while(i != _notifications.end()) {
-    if(!bufferId.isValid() || (*i).bufferId == bufferId) {
+    if(!bufferId.isValid() || i->bufferId == bufferId) {
       foreach(AbstractNotificationBackend *backend, _notificationBackends)
-        backend->close((*i).notificationId);
+        backend->close(i->notificationId);
       i = _notifications.erase(i);
     } else ++i;
   }
@@ -150,17 +147,16 @@ void QtUi::notificationActivated(uint notificationId) {
   if(notificationId != 0) {
     QList<AbstractNotificationBackend::Notification>::iterator i = _notifications.begin();
     while(i != _notifications.end()) {
-      if((*i).notificationId == notificationId) {
-        BufferId bufId = (*i).bufferId;
+      if(i->notificationId == notificationId) {
+        BufferId bufId = i->bufferId;
         if(bufId.isValid())
           Client::bufferModel()->switchToBuffer(bufId);
-        foreach(AbstractNotificationBackend *backend, _notificationBackends)
-          backend->close(notificationId);
-        _notifications.erase(i);
         break;
-      } else ++i;
+      }
+      ++i;
     }
   }
+  closeNotification(notificationId);
 
   mainWindow()->forceActivated();
 }