+ #left click profiles show for the tray
+ self.trayIcon.activated.connect(self.showTrayProfiles)
+
+
+ def showTrayProfiles(self,reason):
+ """ Pops up a system tray profile Manager with a list of activable profiles and an
+ action to add a new One """
+
+ if reason in (QtGui.QSystemTrayIcon.Trigger, QtGui.QSystemTrayIcon.DoubleClick):
+ self.menuProfiles = QMenuToolTip()
+ self.menuProfiles.setTitle("Profiles")
+ QtCore.QCoreApplication.setAttribute(QtCore.Qt.AA_DontShowIconsInMenus, False)
+
+ #Get profiles from the ProfHandler embedded in the gui
+ profiles = self.profileManager.getProfilesList()
+
+ for prpath in profiles:
+ pr = os.path.basename(prpath)
+ receiver = self.activateProfileAction(prpath)
+ menuItem_Profile = self.menuProfiles.addAction(pr)
+ if self.profileManager.isCurrentProfile(prpath):
+ menuItem_Profile.setIcon(QtGui.QIcon(appconf.cpicon))
+
+ #Using lambda function to pass additional arguments to the function, in this case the path of the profile
+ self.connect(menuItem_Profile, SIGNAL('triggered()'), receiver)
+ #set menu item ToolTip
+ menuItem_Profile.setToolTip("Activate profile: "+pr)
+
+ self.menuProfiles.addAction(menuItem_Profile)
+
+ self.menuProfiles.addSeparator()
+ #action and menu item for adding a New Profile
+ self.menuProfiles.addAction(self.addProfile)
+
+ self.menuProfiles.activateWindow()
+ self.menuProfiles.popup(QtGui.QCursor.pos())
+
+ def activateProfileAction(self, pr):
+ """ Returns a callable to be passed as an action for the switching profile mechanism
+ to self.connect(menuItem_Profile...
+ It compiles a function with a profile name as argument and also handle the displaying of errors."""
+
+ def f():
+ try:
+ self.profileManager.activateProfile(pr)
+ except AppError, e:
+ self.showError(str(e))
+ return f
+
+ def addProfile(self):
+ """ Gui frontend to add a new Profile, it requests the user a profile name
+ through a QInputDialog and creates a new profile with the help of the ProfHandler embedded in the Gui """
+
+ self.setWindowTitle("Add New Profile - Dboxswitch - dropbox profile switcher")
+ self.resize(300, 100)
+ text, ok = QtGui.QInputDialog.getText(self, 'Input Dialog',
+ 'Enter profile name:')
+ if ok:
+ try:
+ self.profileManager.addProfile(unicode(text))
+ except AppError, e:
+ self.showError(str(e))
+
+ def showError(self, err):
+ """ Display an error message through a QErrorMessage """
+
+ self.setWindowTitle("Error - Dboxswitch - dropbox profile switcher")
+ self.resize(200, 100)
+ err = QtGui.QErrorMessage.showMessage(QtGui.QErrorMessage.qtHandler(), "Error: "+err)