Пример #1
0
 def deactivate(self):
     try:
         get_notification_center().disconnectPeerAppended(self.peer_update)
         get_notification_center().disconnectPeerUpdated(self.peer_update)
     except:
         self.logger.warning("Problem while disconnecting signals", exc_info=1)
     iface_called_plugin.deactivate(self)    
Пример #2
0
 def newSetter(self, action, category, *args, **kwargs):
     pluginName = action.getPluginName()
     actionName = action.getName()
     if "applyImmediately" in kwargs:
         applyImmediately = kwargs["applyImmediately"]
         del kwargs["applyImmediately"]
     else:
         applyImmediately = True
         
     if "categoryPolicy" in kwargs:
         categoryPolicy = kwargs["categoryPolicy"]
         del kwargs["categoryPolicy"]
     else:
         categoryPolicy = False
     
     if applyImmediately:
         # check if modification is in progress
         settings = self._getActionDict(pluginName, actionName, self._modifications)
         if settings is not None:
             # apply to modified
             if categoryPolicy is not self.CATEGORY_NEVER:
                 settings = self._initModification(action, category, actionDictSource=self._modifications)
             func(self, action, category, settingsDict=settings, *args, **kwargs)
         # apply to stored settings
         settings = self._initModification(action, category, actionDictSource=self._settings, categoryPolicy=categoryPolicy)
         func(self, action, category, settingsDict=settings, *args, **kwargs)
         
         get_notification_center().emitPrivacySettingsChanged(action.getPluginName(), action.getName())
     else:
         # only add to modification dict
         settings = self._initModification(action, category, actionDictSource=self._modifications, categoryPolicy=categoryPolicy)
         func(self, action, category, settingsDict=settings, *args, **kwargs)
Пример #3
0
    def create_widget(self, parent):
        from PyQt4.QtGui import QSortFilterProxyModel
        from PyQt4.QtCore import Qt, QTimer
        from lunchinator.table_widget import TableWidget
        from messages_table.messages_table_model import MessagesTableModel

        self.messagesTable = TableWidget(
            parent, "Send Message", self.sendMessageClicked, placeholderText="Enter a message", sortingEnabled=False
        )

        # initialize messages table
        self.messagesModel = MessagesTableModel(parent)
        self.messagesTable.setModel(self.messagesModel)
        self.messagesTable.setColumnWidth(0, 120)
        self.messagesTable.setColumnWidth(1, 90)

        get_notification_center().connectMessagePrepended(self.messagesModel.messagePrepended)
        get_notification_center().connectDisplayedPeerNameChanged(self.messagesModel.updateSenders)

        self._dailyTrigger = QTimer(parent)
        self._dailyTrigger.timeout.connect(self._updateTimes)
        self._dailyTrigger.setSingleShot(True)
        self._updateDailyTrigger()

        return self.messagesTable
Пример #4
0
 def addGroup(self, group_name):
     """adds a new group 
     (done by the lunch server thread)"""
     if group_name not in self._groups:
         self._groups.add(group_name)
         # TODO: what was the second parameter supposed to be?
         get_notification_center().emitGroupAppended(group_name, self._groups)
Пример #5
0
 def _addMember(self, pID):
     if pID not in self._memberIDs:
         self.logger.debug("Peer %s is a member", pID)
         self._memberIDs.add(pID)
         get_notification_center().emitMemberAppended(pID, deepcopy(self.getPeerInfo(pID=pID, lock=False)))
     else:  # something may have changed for the member data
         get_notification_center().emitMemberUpdated(pID, deepcopy(self.getPeerInfo(pID=pID, lock=False)))
Пример #6
0
 def checkForUpdates(self, forced=False):
     """Checks each repository for updates.
     
     Returns a set of paths where updates are available.
     forced -- If True, repositories with autoUpdate==False are checked, too.
     """
     with self._lock:
         # make a copy s.t. we don't have to lock the repos all the time
         repos = deepcopy(self._externalRepos)
         
     outdated = set()
     upToDate = set()
     gh = GitHandler(getCoreLogger())
     for path, _active, autoUpdate in repos:
         if forced or autoUpdate:
             
             if gh.needsPull(path=path):
                 outdated.add(path)
             else:
                 upToDate.add(path)
             
     with self._lock:
         self._outdated -= upToDate
         self._outdated.update(outdated)
         
         self._upToDate -= outdated
         self._upToDate.update(upToDate)
         
     if outdated:
         get_notification_center().emitOutdatedRepositoriesChanged()
     if upToDate:
         get_notification_center().emitUpToDateRepositoriesChanged()
     return outdated
    def testMemberRemovalLock(self):
        get_notification_center().connectMemberRemoved(self.connect_testMemberRemovalLock)

        print "Removing myself as Member"
        mIPs = get_peers().getPeerIPs(get_settings().get_ID())
        print "Using IPs:", mIPs
        get_peers().removeMembersByIP(mIPs)
Пример #8
0
 def _installReady(self):
     """Makes the install button enabled/disabled"""
     self._install_ready = True
     get_notification_center().emitApplicationUpdate()
     displayNotification("New Version Available", "Install via Update Plugin", self.logger)
     if self._ui != None:
         self._ui.appInstallReady()    
Пример #9
0
 def __init__(self):
     cmd.Cmd.__init__(self)
     LunchServerController.__init__(self)
     
     self.logger = newLogger("cli")
     self.prompt = "> "
     self.commands = set(["exit"])
     self.addModule(CLIMessageHandling())  
     self.addModule(CLIOptionHandling())
     self.addModule(CLIPluginHandling(self))
     self.addModule(CLIPrivacyHandling())
     self.addModule(CLILoggingHandling())
     
     get_server().initialize(self)
     
     if get_settings().get_plugins_enabled():
         for pluginInfo in get_plugin_manager().getAllPlugins():
             if pluginInfo.plugin_object.is_activated:
                 self.addModule(pluginInfo.plugin_object)
             
     get_notification_center().connectApplicationUpdate(self.notifyUpdates)
             
     self.exitCode = 0
     # if serverStopped is called, we can determine if it was a regular exit.
     self.cleanExit = False
     self.initialized = False
Пример #10
0
 def discard(self, notify=True):
     """Discards all modifications since the last save"""
     with self._lock:
         for pluginName, pluginDict in self._modifications.iteritems():
             for actionName, _actionDict in pluginDict.iteritems():
                 if notify:
                     get_notification_center().emitPrivacySettingsDiscarded(pluginName, actionName)
         self._modifications = {}
Пример #11
0
 def closeEvent(self, event):
     if not self.getChatWidget().canClose():
         event.ignore()
     else:
         self.windowClosing.emit(self._otherID)
         get_notification_center().disconnectDisplayedPeerNameChanged(self._displayedPeerNameChanged)
         self.getChatWidget().finish()
         event.accept()
Пример #12
0
 def set_group(self, value, init=False):
     from lunchinator import get_server
     oldGroup = self._group
     self._group = value
     if not init:
         getCoreLogger().info("Changing Group: '%s' -> '%s'", oldGroup, self._group)
         get_server().changeGroup(unicode(value))
         get_notification_center().emitGroupChanged(oldGroup, self._group)
 def processMessage(self, xmsg, addr, eventTime, newPeer, fromQueue):
     """ process any message event, including lunch calls
     @type xmsg: extMessageIncoming
     @type addr: unicode
     @type eventTime: float
     @type newPeer: bool
     @type fromQueue: bool
     """
     mtime = localtime(eventTime)
     t = strftime("%a, %d %b %Y %H:%M:%S", mtime).decode("utf-8")        
     msg = xmsg.getPlainMessage()
     
     if not newPeer:
         with get_peers():
             m = get_peers().getPeerInfo(pIP=addr, lock=False)
             peerName = get_peers().getDisplayedPeerName(pIP=addr, lock=False)
         if m is None:
             getCoreLogger().error("Error processing message: info dict is None")
         else:
             if peerName is None:
                 peerName = m.get(LunchPeers.PEER_NAME_KEY, "<unknown>")
             getCoreLogger().info("%s: [%s (%s)] %s", t, peerName, m[LunchPeers.PEER_ID_KEY], msg)
             self._insertMessage(mtime, m[LunchPeers.PEER_ID_KEY], msg)
             get_notification_center().emitMessagePrepended(mtime, m[LunchPeers.PEER_ID_KEY], msg)
     else:
         m = {u"ID": addr}
     
     
     processLunchCall = False
     #deprecated:
     self.processPluginCall(addr, lambda p, ip, member_info: p.process_message(msg, ip, member_info), newPeer, fromQueue)
     
     #the next block could be one huge statement, but for readability I leave it as is
     if get_settings().get_lunch_trigger() in msg.lower():
         # the message contains the lunch keyword
         if eventTime - self.last_lunch_call > get_settings().get_mute_timeout() or \
            fromQueue and self.last_lunch_call == eventTime:
             # it has not been reported before 
             # the call has not been during the mute_timeout or
             # this is a queued lunch call that previously wasn't muted
             diff = getTimeDifference(get_settings().get_alarm_begin_time(), get_settings().get_alarm_end_time(), getCoreLogger())
             if diff == None or 0 < diff:
                 # either the time format is invalid or we are within the alarm time
                 processLunchCall = True
             else:
                 diff = getTimeDifference(get_settings().get_next_lunch_begin(), get_settings().get_next_lunch_end(), getCoreLogger())
                 if diff == None or 0 < diff:
                     # either the time format is invalid or we are within the free for lunch time
                     processLunchCall = True
         
         if processLunchCall:
             self.last_lunch_call = eventTime
             #deprecated:
             self.processPluginCall(addr, lambda p, ip, member_info: p.process_lunch_call(msg, ip, member_info), newPeer, fromQueue)
         else:
             getCoreLogger().debug("messages will not trigger alarm: %s: [%s] %s until %s (unless you change the setting, that is)", t, m, msg, strftime("%H:%M:%S", localtime(eventTime + get_settings().get_mute_timeout())))
     
     self.processPluginCall(addr, lambda p, ip, member_info: p.process_group_message(xmsg, ip, member_info, processLunchCall), newPeer, fromQueue)
Пример #14
0
 def setGlobalLevel(cls, newLevel):
     if newLevel == cls._globalLevel:
         return
     cls._globalLevel = newLevel
     for name, logger in cls._loggers.iteritems():
         if name not in cls._specificLevels:
             logger.setLevel(newLevel)
     from lunchinator import get_notification_center
     get_notification_center().emitLoggingLevelChanged(None, newLevel)
 def _pluginActivated(self, pluginName, category):
     pluginName = convert_string(pluginName)
     category = convert_string(category)
     pi = get_plugin_manager().getPluginByName(pluginName, category)
     if pi:
         with self._lock:
             added = self._addActionsForPlugin(pi)
         if added:
             get_notification_center().emitPeerActionsAdded(added)
Пример #16
0
 def deactivate(self):
     """
     Just call the parent class's method
     """
     if len(self._supported_dbms)>0:
         get_notification_center().disconnectDBSettingChanged(self.connect_to_db)
     self.option_widgets = {}
     removeLogger(self.plugin_name)
     IPlugin.deactivate(self)
 def _pluginDeactivated(self, pluginName, category):
     pluginName = convert_string(pluginName)
     category = convert_string(category)
     pi = get_plugin_manager().getPluginByName(pluginName, category)
     if pi:
         with self._lock:
             removed = self._removeActionsForPlugin(pi)
         if removed:
             get_notification_center().emitPeerActionsRemoved(removed)
Пример #18
0
 def __init__(self, parent):
     super(ErrorLogDialog, self).__init__(parent, Qt.WindowStaysOnTopHint)
     self._empty = True
     
     self._initUI()
     self.setWindowTitle("Error")
     get_notification_center().connectLogMessage(self._checkLogMessage)
     
     for record in getCachedLogRecords():
         self._checkLogMessage(record)
Пример #19
0
 def __init__(self, parent, logger, ownName, otherName, ownPicFile, otherPicFile, otherID, sendAction):
     super(ChatWindow, self).__init__(parent)
     self.logger = logger
     self._otherID = otherID
     self._chatWidget = ChatWidget(self, logger, ownName, otherName, ownPicFile, otherPicFile, otherID, sendAction)
     self.setCentralWidget(self._chatWidget)
     self.setWindowTitle(otherName)
     self.setWindowIcon(QIcon(get_settings().get_resource("images", "lunchinator_chat.png")))
     
     get_notification_center().connectDisplayedPeerNameChanged(self._displayedPeerNameChanged)
Пример #20
0
    def removePeer(self, pID):
        with self._lock:
            if pID not in self._idToIp:
                return
            pIPs = self._idToIp.pop(pID)
            self._removeMember(pID)
            for pIP in pIPs:
                self._peer_info.pop(pIP)

        get_notification_center().emitPeerRemoved(pID)
Пример #21
0
    def __init__(self, controller):
        super(LunchinatorWindow, self).__init__(None)

        self.guiHandler = controller
        self.setWindowTitle("Lunchinator")
        self.setWindowIcon(QIcon(get_settings().get_resource("images", "lunchinator.png"))) 

        self.setDockNestingEnabled(True)
        self.setTabPosition(Qt.AllDockWidgetAreas, QTabWidget.North)
        
        self.pluginNameToDockWidget = {}
        self.objectNameToPluginName = {}
        self.pluginNameToMenus = {}
        self.settings = QSettings(get_settings().get_config("gui_settings.ini"), QSettings.IniFormat)
        
        savedGeometry = self.settings.value("geometry", None)
        savedState = self.settings.value("state", None)
        self.locked = self.settings.value("locked", QVariant(False)).toBool()
        
        self._prepareMenuBar()
        
        if savedState == None:
            # first run, create initial state
            get_plugin_manager().activatePluginByName(u"Simple View", "gui")
            get_plugin_manager().activatePluginByName(u"Auto Update", "general")
        
        # add plugins
        try:
            if get_settings().get_plugins_enabled():
                for pluginInfo in get_plugin_manager().getPluginsOfCategory("gui"):
                    if pluginInfo.plugin_object.is_activated:
                        self.addPluginWidget(pluginInfo.plugin_object, pluginInfo.name, noTabs=True)
        except:
            getCoreLogger().exception("while including plugins %s", str(sys.exc_info()))
        
        if savedGeometry != None:
            self.restoreGeometry(savedGeometry.toByteArray())
        else:
            self.centerOnScreen()
        
        if savedState != None:
            self.restoreState(savedState.toByteArray())

        get_notification_center().connectPluginActivated(self._pluginActivated)
        get_notification_center().connectPluginWillBeDeactivated(self._pluginWillBeDeactivated)
        
        if len(self.pluginNameToDockWidget) == 0 and get_settings().get_plugins_enabled():
            # no gui plugins activated, show about plugins
            get_plugin_manager().activatePluginByName(u"About Plugins", "gui")
        
        if self.locked:
            self.lockDockWidgets()
        
        # prevent from closing twice
        self.closed = False
Пример #22
0
 def finish(self):
     get_notification_center().disconnectPeerAppended(self._peerUpdated)
     get_notification_center().disconnectPeerUpdated(self._peerUpdated)
     get_notification_center().disconnectPeerRemoved(self._peerRemoved)
     get_notification_center().disconnectAvatarChanged(self._avatarChanged)
     get_notification_center().disconnectDisplayedPeerNameChanged(self._displayedPeerNameChanged)
     
     if self._typingTimer is not None:
         self._typingTimer.stop()
         self._typingTimer.deleteLater()
         self._typingTimer = None
Пример #23
0
 def __init__(self, parent):
     super(listPluginsWidget, self).__init__(parent)
     self.ui = Ui_Plugins()
     self.ui.setupUi(self)
     
     self.p_info = self.get_plugin_info()
     
     self.create_plugin_view(False)
     self.ui.pluginView.setCurrentRow(0) 
     
     get_notification_center().connectPluginActivated(self.update_plugin_view)  
     get_notification_center().connectPluginDeactivated(self.update_plugin_view)  
Пример #24
0
 def setCustomName(self, peerID, customName, infoDict=None):
     """Called from lunch_peers, no locking"""
     self._checkCache(peerID)
     peerName, oldCustomName = self._peerNameCache[peerID]
     if peerName == None:
         self.logger.error("Trying to specify custom name for unknown peer")
         return
     self._peerNameCache[peerID] = (peerName, customName)
         
     if oldCustomName != customName:
         self._db.execute("UPDATE CORE_PEER_NAMES SET CUSTOM_NAME = ? WHERE PEER_ID = ?", customName, peerID)
         get_notification_center().emitDisplayedPeerNameChanged(peerID, self.getDisplayedPeerName(peerID), infoDict)
Пример #25
0
 def __init__(self, parent, logger):
     super(ConsoleWidget, self).__init__(parent)
     
     self.logger = logger
     self._errorColor = QVariant(QColor(180, 0, 0))
     self._warningColor = QVariant(QColor(170, 100, 0))
     self._records = []
     
     self._initModel()
     self._initUI()
     
     get_notification_center().connectLogMessage(self._addLogMessage)
    def __init__(self, parent):
        super(LunchinatorSettingsDialog, self).__init__(parent, Qt.Dialog)

        self.setWindowTitle("Lunchinator Settings")
        # self.setModal(True)
        self.setResult(QDialog.Rejected)

        contentLayout = QVBoxLayout(self)

        self.nb = ComboTabWidget(self)
        self.nb.setTabPosition(QTabWidget.North)

        self.widget_containers = {}
        self.widget_names = []
        try:
            if get_settings().get_plugins_enabled():
                for pluginInfo in get_plugin_manager().getAllPlugins():
                    if pluginInfo.plugin_object.is_activated:
                        self.addPlugin(pluginInfo.plugin_object, pluginInfo.name, pluginInfo.category)
        except:
            getCoreLogger().exception("while including plugins in settings window")

        contentLayout.addWidget(self.nb)
        # d.get_content_area().pack_start(nb, True, True, 0)
        if self.nb.count() > 0:
            self.nb.setCurrentIndex(0)
            # show first widget
            self.nb.widget(0).showContents()

        buttonBox = QDialogButtonBox(Qt.Horizontal, self)

        saveButton = QPushButton("Save", self)
        # saveButton.setAutoDefault(True)
        saveButton.clicked.connect(self.savePressed)
        buttonBox.addButton(saveButton, QDialogButtonBox.AcceptRole)

        cancelButton = QPushButton("Cancel", self)
        cancelButton.clicked.connect(self.cancelPressed)
        buttonBox.addButton(cancelButton, QDialogButtonBox.RejectRole)

        applyButton = QPushButton("Apply", self)
        applyButton.clicked.connect(self.applyPressed)
        buttonBox.addButton(applyButton, QDialogButtonBox.ApplyRole)

        discardButton = QPushButton("Discard", self)
        discardButton.clicked.connect(self.discardPressed)
        buttonBox.addButton(discardButton, QDialogButtonBox.ApplyRole)

        contentLayout.addWidget(buttonBox)

        get_notification_center().connectPluginActivated(self._pluginActivated)
        get_notification_center().connectPluginWillBeDeactivated(self._pluginWillBeDeactivated)
Пример #27
0
    def destroy_widget(self):
        if self._dailyTrigger != None:
            self._dailyTrigger.timeout.disconnect(self._updateTimes)
            self._dailyTrigger.stop()
            self._dailyTrigger.deleteLater()

        get_notification_center().disconnectMessagePrepended(self.messagesModel.messagePrepended)
        get_notification_center().disconnectDisplayedPeerNameChanged(self.messagesModel.updateSenders)

        self.messagesModel = None
        self.messagesTable = None

        iface_gui_plugin.destroy_widget(self)
Пример #28
0
 def _addPeerIPtoID(self, pID, ip):
     if pID not in self._idToIp:
         self._idToIp[pID] = [ip]
         if self._peerNames is not None:
             self._peerNames.addPeerName(pID, self._peer_info[ip])
         get_notification_center().emitPeerAppended(pID, deepcopy(self._peer_info[ip]))
     else:
         # last one is last seen one
         self._idToIp[pID].append(ip)
         # workaround to get the IP over to the slots
         cp = deepcopy(self._peer_info[ip])
         cp["triggerIP"] = ip
         get_notification_center().emitPeerUpdated(pID, cp)
Пример #29
0
 def activate(self):
     """
     Call the parent class's activation method
     """
     IPlugin.activate(self)
     
     self.logger = newLogger(self.plugin_name)
     self._initOptions()
     self._readOptionsFromFile()
     if len(self._supported_dbms)>0:
         get_notification_center().connectDBSettingChanged(self.connect_to_db)
         self.connect_to_db()
     return
Пример #30
0
    def _removePeerIPfromID(self, pID, ip):
        self.logger.debug("Removing %s from ID: %s", ip, pID)
        self._idToIp[pID].remove(ip)

        if 0 == len(self._idToIp[pID]):
            # no IP associated with that ID -> remove peer
            # remove member first
            self._removeMember(pID)
            self._idToIp.pop(pID)
            get_notification_center().emitPeerRemoved(pID)
        else:
            existing_ip = self._idToIp[pID][0]
            get_notification_center().emitPeerUpdated(pID, deepcopy(self._peer_info[existing_ip]))