示例#1
0
    def __init__(self, auth, conversation_id, settings, version, parent = None):
        QDialog.__init__(self, parent)
        self.ui = cg.Ui_Dialog()
        self.ui.setupUi(self)
        
        self.settings = settings
        self.auth = auth
        self.version = version
        
        # Initialize signal mappers for buttons and lists for buttons pointers
        self.context_buttons_mapper = QSignalMapper(self)
        self.context_buttons_list = []
        self.destroy_buttons_mapper = QSignalMapper(self)
        self.destroy_buttons_list = []
        self.redent_buttons_mapper = QSignalMapper(self)
        self.redent_buttons_list = []
        self.like_buttons_mapper = QSignalMapper(self)
        self.like_buttons_list = []
        self.dentid_buttons_mapper = QSignalMapper(self)
        self.dentid_buttons_list = []
        
        self.ui.context.setSortingEnabled(True)
        self.ui.context.sortByColumn(2, Qt.DescendingOrder)
        for column in range(2, 6):
            self.ui.context.setColumnHidden(column, True)
        self.ui.context.setColumnWidth(0, 65)
        self.ui.context.itemActivated.connect(self.reply_to_dent)

        conversation = self.auth.get_conversation(conversation_id)
        
        self.list_handler = list_handler.List_Handler(self.callback)
        
        self.list_item = list_item.list_item()
        self.list_handler.add_data("conversation", conversation, self.settings["server"])
        self.connect_buttons()
示例#2
0
    def __init__(self, parent=None):
        QWidget.__init__(self, parent)
        self.ui = MainWindow.Ui_MainWindow()
        self.ui.setupUi(self)
        self.ui.statusbar.hide()

        self.appVersion = "0.1-dev"

        # Setting QTDenter path
        common.set_qtdenter_path()

        # Some variables
        self._hidden = 0
        self.inserted_timeline_dents_ids = []
        self.inserted_mentions_dents_ids = []
        self._new_direct_messages = 0
        self._new_mentions = 0
        self._changed_credentials = False
        self.filters = {}
        # Set default filters
        self._filters_state = ["timeline", "mentions"]

        # Set QTextCodec explicitly. Some disadvantages for rarely used
        # languages, but no problems for others.
        QTextCodec.setCodecForCStrings(QTextCodec.codecForName("UTF-8"))

        # Tray icon
        self.icon = {}
        if not os.path.exists(common.QTDENTER_PATH + "/imgs/qtdenter.png"):
            self.icon["qicon"] = QIcon("/usr/share/pixmaps/qtdenter.png")
            self.icon["path"] = "/usr/share/pixmaps/qtdenter.png"
        else:
            self.icon["qicon"] = QIcon(common.QTDENTER_PATH +
                                       "/imgs/qtdenter.png")
            self.icon["path"] = common.QTDENTER_PATH + "/ui/imgs/qtdenter.png"

        self.trayIcon = QSystemTrayIcon(self.icon["qicon"], self)
        self.trayIcon.setVisible(True)
        self.connect(self.trayIcon,
                     SIGNAL("activated(QSystemTrayIcon::ActivationReason)"),
                     self.check_for_visibility)

        # Tray menu
        menu = QMenu(parent)
        menu.addAction("Show/Hide", self.check_for_visibility)
        menu.addSeparator()
        #menu.addAction("Options", self.show_options)
        #menu.addSeparator()
        menu.addAction("Exit", self.close_from_tray)
        self.trayIcon.setContextMenu(menu)

        # Reading settings and fill settings dict
        self.settings = {}
        if not os.path.exists(os.path.expanduser("~/.config/qtdenter")):
            os.mkdir(os.path.expanduser("~/.config/qtdenter"))
            os.system("touch ~/.config/qtdenter/qsettings.conf")
        if not os.path.exists(
                os.path.expanduser("~/.local/share/qtdenter/avatars/temp")):
            os.makedirs(
                os.path.expanduser("~/.local/share/qtdenter/avatars/temp"))

        if not os.path.exists(cachepath):
            os.mkdir(cachepath)

        try:
            self.qsettings = QSettings("qtdenter", "qsettings")
            self.settings["user"] = self.qsettings.value("user").toString()
            self.settings["password"] = self.qsettings.value(
                "password").toString()
            self.settings["server"] = self.qsettings.value("server").toString()
            self.settings["useSecureConnection"] = self.qsettings.value(
                "useSecureConnection").toString()
            self.settings["isSingle"] = self.qsettings.value(
                "isSingle").toString()
            self.settings["deleteAllFromCacheOnExit"] = self.qsettings.value(
                "deleteAllFromCacheOnExit").toString()
            self.settings["updateInterval"] = self.qsettings.value(
                "updateInterval").toString()
            self.settings["last_dent_id"] = self.qsettings.value(
                "last_dent_id").toString()

        except:
            QMessageBox.critical(self, "denter - No accounts",
                                 "Setup an account in Options!")

        try:
            self.restoreGeometry(
                self.qsettings.value("geometry").toByteArray())
            self.restoreState(self.qsettings.value("state").toByteArray())
        except:
            pass

        try:
            self.settings["remember_last_dent_id"] = self.qsettings.value(
                "remember_last_dent_id").toString()
            self.settings["fetch_on_startup"] = self.qsettings.value(
                "fetch_on_startup").toString()
        except:
            self.settings["remember_last_dent_id"] = "0"
            self.settings["fetch_on_startup"] = "20"

        try:
            self.settings["player"] = self.qsettings.value("player").toString()
            self.settings["player_string"] = self.qsettings.value(
                "player_string").toString()
            self.settings["mpd_port"] = self.qsettings.value(
                "mpd_port").toString()
            self.settings["mpd_host"] = self.qsettings.value(
                "mpd_host").toString()
        except:
            self.settings["player"] = None
            self.settings[
                "player_string"] = "!listening to: $artist - $track #$player"
            self.settings["mpd_port"] = "6600"
            self.settings["mpd_host"] = "localhost"

        try:
            self._filters_state = self.qsettings.value(
                "filters_state").toString()
            self._filters_state = self._filters_state.split(":")
        except:
            print "Failed to restore filters state"

        # Connecting menu actions
        self.ui.action_Options.triggered.connect(self.show_options_dialog)
        self.ui.action_Exit.triggered.connect(self.close_from_menu)
        self.ui.action_About_Denter.triggered.connect(self.show_about)
        self.ui.actionStatistics.triggered.connect(self.show_information)
        self.ui.actionSpam_Music_data.triggered.connect(self.spam_music)
        self.ui.action_Update_all.triggered.connect(self.update_timelines)
        self.ui.action_Mark_all_unread.triggered.connect(self.mark_all_as_read)

        # Connecting some signals
        self.connect(self, SIGNAL("ShowForm()"), self.check_for_visibility)
        self.connect(self, SIGNAL("HideForm()"), self.check_for_visibility)
        self.connect(self, SIGNAL("ShowOptions()"), self.show_options_dialog)
        self.connect(self, SIGNAL("Close()"), self.close_from_tray)

        # New post toolbar icon
        newPostIcon = iconFromTheme("add")
        newPost = QAction(newPostIcon, "New post", self)
        newPost.setShortcut("Ctrl+N")
        newPost.triggered.connect(self.post_status_dialog)

        # New direct message toolbar icon
        new_direct_message_icon = iconFromTheme("no-new-messages")
        new_direct_message = QAction(new_direct_message_icon,
                                     "New direct message", self)
        new_direct_message.setShortcut("Ctrl+D")
        new_direct_message.triggered.connect(self.post_direct_message_dialog)

        # Timelines reload toolbar icon
        reloadTimelinesIcon = iconFromTheme("reload")
        reloadTimelines = QAction(reloadTimelinesIcon, "Reload all timelines",
                                  self)
        reloadTimelines.setShortcut("Ctrl+R")
        reloadTimelines.triggered.connect(self.update_timelines)

        # Mark all read icon
        mark_all_read_icon = iconFromTheme("dialog-ok")
        mark_all_read = QAction(mark_all_read_icon,
                                "Mark all unread dents as read", self)
        mark_all_read.setShortcut("Ctrl+X")
        mark_all_read.triggered.connect(self.mark_all_as_read)

        # Options toolbar icon
        optionsIcon = iconFromTheme("document-properties")
        options = QAction(optionsIcon, "Options", self)
        options.setShortcut("Ctrl+P")
        options.triggered.connect(self.show_options_dialog)

        # Spacer widget, making last updated time label in toolbar to align
        # strictly right
        spacerWidget = QWidget()
        spacerWidget.setSizePolicy(QSizePolicy.Expanding,
                                   QSizePolicy.Preferred)

        # Last updated label
        self.time_updated_action = QLabel()

        # Adding everything to toolbar
        self.ui.toolBar.addAction(newPost)
        self.ui.toolBar.addAction(new_direct_message)
        self.ui.toolBar.addSeparator()
        self.ui.toolBar.addAction(reloadTimelines)
        self.ui.toolBar.addAction(mark_all_read)
        self.ui.toolBar.addSeparator()
        self.ui.toolBar.addAction(options)
        self.ui.toolBar.addWidget(spacerWidget)
        self.ui.toolBar.addWidget(self.time_updated_action)

        # Setting icons
        self.ui.timeline_btn.setIcon(
            QIcon(common.QTDENTER_PATH + "/imgs/timeline.png"))
        self.ui.mentions_btn.setIcon(
            QIcon(common.QTDENTER_PATH + "/imgs/mentions.png"))
        self.ui.directs_btn.setIcon(
            QIcon(common.QTDENTER_PATH + "/imgs/directs.png"))

        # Adding accounts
        self.ui.no_accounts_btn.hide()

        self.btn = QPushButton()
        self.btn.setIcon(QIcon(common.QTDENTER_PATH + "/imgs/identica.png"))
        self.btn.setText(self.settings["server"])

        self.ui.accounts_layout.addWidget(self.btn)

        if "timeline" in self._filters_state:
            self.ui.timeline_btn.setChecked(True)
        if "mentions" in self._filters_state:
            self.ui.mentions_btn.setChecked(True)
        if "directs" in self._filters_state:
            self.ui.directs_btn.setChecked(True)

        self.ui.timeline_btn.clicked.connect(self.change_filters)
        self.ui.mentions_btn.clicked.connect(self.change_filters)
        self.ui.directs_btn.clicked.connect(self.change_filters)

        # Defining list_handler instance
        self.list_handler = list_handler.List_Handler(
            callback=self.lists_callback)

        # Set some options to timeline list
        self.ui.timeline_list.setSortingEnabled(True)
        self.ui.timeline_list.sortByColumn(2, Qt.DescendingOrder)
        for column in range(2, 6):
            self.ui.timeline_list.setColumnHidden(column, True)
        self.ui.timeline_list.setColumnWidth(0, 65)
        self.ui.timeline_list.itemActivated.connect(self.reply_to_dent)
        self.ui.timeline_list.itemSelectionChanged.connect(
            self.change_item_read_state)

        # Defining list_item instance, that generates items for lists
        self.list_item = list_item.list_item()

        # Init notifications
        try:
            pynotify.init(sys.argv[0])
            print "Notifier loaded"
        except:
            print "Failed to init pynotify"

        self.show()

        # Initialize auther and get timelines for first time
        try:
            self.init_connector()
        except:
            print "No auth data specified"

        try:
            self.initialize_button_mappers()

            opts = {
                "count": str(self.settings["fetch_on_startup"]),
                "name": self.settings["user"]
            }

            if self.settings["remember_last_dent_id"] == "1":
                # Getting last dent ID from server
                temp = self.auth.get_home_timeline(opts)
                # Calculation count of dents we will download on startup
                count = temp[0]["id"] - int(self.settings["last_dent_id"])

                if count == 0:
                    count = 20
                else:
                    pass

                opts = {"count": str(count), "name": self.settings["user"]}
        except:
            print "Can't specify options!"

        try:
            home_timeline = self.auth.get_home_timeline(opts)
            self.list_handler.add_data("home", home_timeline,
                                       self.settings["server"])
        except:
            print "Can't get home timeline. WTF?"

        try:
            mentions = self.auth.get_direct_messages(opts)
            self.list_handler.add_data("direct_messages", mentions,
                                       self.settings["server"])
            if self.settings["remember_last_dent_id"] == "1":
                root = self.ui.timeline_list.invisibleRootItem()
                last_item = root.child(0)
                dent_id = last_item.text(2).split(":")[0]
                self.qsettings.setValue("last_dent_id", dent_id)
            self.qsettings.sync()
        except:
            print "Can't get direct messages. WTF?"

        try:
            # Connect buttons
            self.connect_buttons()
        except:
            print "Failed to connect buttons!"

        # Init timer
        self.start_timer(self.settings["updateInterval"])

        # Init "Now Playing"
        self.np = now_playing.Now_Playing(self.settings)

        # Get max characters count from server
        try:
            server_data = self.auth.get_server_config("config")
            self.settings["messageLength"] = server_data["site"]["textlimit"]
        except:
            self.settings["messageLength"] = "140"
示例#3
0
    def __init__(self, parent=None):
        QWidget.__init__(self, parent)
        self.ui = MainWindow.Ui_MainWindow()
        self.ui.setupUi(self)
        self.ui.statusbar.hide()

        self.appVersion = "0.1-dev"
        
        # Setting QTDenter path
        common.set_qtdenter_path()
        
        # Some variables
        self._hidden = 0
        self.inserted_timeline_dents_ids = []
        self.inserted_mentions_dents_ids = []
        self._new_direct_messages = 0
        self._new_mentions = 0
        self._changed_credentials = False
        self.filters = {}
        # Set default filters
        self._filters_state = ["timeline", "mentions"]
        
        # Set QTextCodec explicitly. Some disadvantages for rarely used
        # languages, but no problems for others.
        QTextCodec.setCodecForCStrings(QTextCodec.codecForName("UTF-8"))
        
        # Tray icon
        self.icon = {}
        if not os.path.exists(common.QTDENTER_PATH + "/imgs/qtdenter.png"):
            self.icon["qicon"] = QIcon("/usr/share/pixmaps/qtdenter.png")
            self.icon["path"] = "/usr/share/pixmaps/qtdenter.png"
        else:
            self.icon["qicon"] = QIcon(common.QTDENTER_PATH + "/imgs/qtdenter.png")
            self.icon["path"] = common.QTDENTER_PATH + "/ui/imgs/qtdenter.png"
            
        self.trayIcon = QSystemTrayIcon(self.icon["qicon"], self)
        self.trayIcon.setVisible(True)
        self.connect(self.trayIcon, SIGNAL("activated(QSystemTrayIcon::ActivationReason)"), self.check_for_visibility)
        
        # Tray menu
        menu = QMenu(parent)
        menu.addAction("Show/Hide", self.check_for_visibility)
        menu.addSeparator()
        #menu.addAction("Options", self.show_options)
        #menu.addSeparator()
        menu.addAction("Exit", self.close_from_tray)
        self.trayIcon.setContextMenu(menu)

        # Reading settings and fill settings dict
        self.settings = {}
        if not os.path.exists(os.path.expanduser("~/.config/qtdenter")):
            os.mkdir(os.path.expanduser("~/.config/qtdenter"))
            os.system("touch ~/.config/qtdenter/qsettings.conf")
        if not os.path.exists(os.path.expanduser("~/.local/share/qtdenter/avatars/temp")):
            os.makedirs(os.path.expanduser("~/.local/share/qtdenter/avatars/temp"))

        if not os.path.exists(cachepath):
            os.mkdir(cachepath)

        try:
            self.qsettings = QSettings("qtdenter", "qsettings")
            self.settings["user"] = self.qsettings.value("user").toString()
            self.settings["password"] = self.qsettings.value("password").toString()
            self.settings["server"] = self.qsettings.value("server").toString()
            self.settings["useSecureConnection"] = self.qsettings.value("useSecureConnection").toString()
            self.settings["isSingle"] = self.qsettings.value("isSingle").toString()
            self.settings["deleteAllFromCacheOnExit"] = self.qsettings.value("deleteAllFromCacheOnExit").toString()
            self.settings["updateInterval"] = self.qsettings.value("updateInterval").toString()
            self.settings["last_dent_id"] = self.qsettings.value("last_dent_id").toString()
            
        except:
            QMessageBox.critical(self, "denter - No accounts", "Setup an account in Options!")

        try:
            self.restoreGeometry(self.qsettings.value("geometry").toByteArray())
            self.restoreState(self.qsettings.value("state").toByteArray())
        except:
            pass
            
        try:
            self.settings["remember_last_dent_id"] = self.qsettings.value("remember_last_dent_id").toString()
            self.settings["fetch_on_startup"] = self.qsettings.value("fetch_on_startup").toString()
        except:
            self.settings["remember_last_dent_id"] = "0"
            self.settings["fetch_on_startup"] = "20"
            
        try:
            self.settings["player"] = self.qsettings.value("player").toString()
            self.settings["player_string"] = self.qsettings.value("player_string").toString()
            self.settings["mpd_port"] = self.qsettings.value("mpd_port").toString()
            self.settings["mpd_host"] = self.qsettings.value("mpd_host").toString()
        except:
            self.settings["player"] = None
            self.settings["player_string"] = "!listening to: $artist - $track #$player"
            self.settings["mpd_port"] = "6600"
            self.settings["mpd_host"] = "localhost"
            
        try:
            self._filters_state = self.qsettings.value("filters_state").toString()
            self._filters_state = self._filters_state.split(":")
        except:
            print "Failed to restore filters state"

        # Connecting menu actions
        self.ui.action_Options.triggered.connect(self.show_options_dialog)
        self.ui.action_Exit.triggered.connect(self.close_from_menu)
        self.ui.action_About_Denter.triggered.connect(self.show_about)
        self.ui.actionStatistics.triggered.connect(self.show_information)
        self.ui.actionSpam_Music_data.triggered.connect(self.spam_music)
        self.ui.action_Update_all.triggered.connect(self.update_timelines)
        self.ui.action_Mark_all_unread.triggered.connect(self.mark_all_as_read)

        # Connecting some signals
        self.connect(self, SIGNAL("ShowForm()"), self.check_for_visibility)
        self.connect(self, SIGNAL("HideForm()"), self.check_for_visibility)
        self.connect(self, SIGNAL("ShowOptions()"), self.show_options_dialog)
        self.connect(self, SIGNAL("Close()"), self.close_from_tray)

        # New post toolbar icon
        newPostIcon = iconFromTheme("add")
        newPost = QAction(newPostIcon, "New post", self)
        newPost.setShortcut("Ctrl+N")
        newPost.triggered.connect(self.post_status_dialog)
        
        # New direct message toolbar icon
        new_direct_message_icon = iconFromTheme("no-new-messages")
        new_direct_message = QAction(new_direct_message_icon, "New direct message", self)
        new_direct_message.setShortcut("Ctrl+D")
        new_direct_message.triggered.connect(self.post_direct_message_dialog)

        # Timelines reload toolbar icon
        reloadTimelinesIcon = iconFromTheme("reload")
        reloadTimelines = QAction(reloadTimelinesIcon, "Reload all timelines", self)
        reloadTimelines.setShortcut("Ctrl+R")
        reloadTimelines.triggered.connect(self.update_timelines)
        
        # Mark all read icon
        mark_all_read_icon = iconFromTheme("dialog-ok")
        mark_all_read = QAction(mark_all_read_icon, "Mark all unread dents as read", self)
        mark_all_read.setShortcut("Ctrl+X")
        mark_all_read.triggered.connect(self.mark_all_as_read)

        # Options toolbar icon
        optionsIcon = iconFromTheme("document-properties")
        options = QAction(optionsIcon, "Options", self)
        options.setShortcut("Ctrl+P")
        options.triggered.connect(self.show_options_dialog)

        # Spacer widget, making last updated time label in toolbar to align
        # strictly right
        spacerWidget = QWidget()
        spacerWidget.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Preferred)

        # Last updated label
        self.time_updated_action = QLabel()

        # Adding everything to toolbar
        self.ui.toolBar.addAction(newPost)
        self.ui.toolBar.addAction(new_direct_message)
        self.ui.toolBar.addSeparator()
        self.ui.toolBar.addAction(reloadTimelines)
        self.ui.toolBar.addAction(mark_all_read)
        self.ui.toolBar.addSeparator()
        self.ui.toolBar.addAction(options)
        self.ui.toolBar.addWidget(spacerWidget)
        self.ui.toolBar.addWidget(self.time_updated_action)
        
        # Setting icons
        self.ui.timeline_btn.setIcon(QIcon(common.QTDENTER_PATH + "/imgs/timeline.png"))
        self.ui.mentions_btn.setIcon(QIcon(common.QTDENTER_PATH + "/imgs/mentions.png"))
        self.ui.directs_btn.setIcon(QIcon(common.QTDENTER_PATH + "/imgs/directs.png"))
        
        # Adding accounts
        self.ui.no_accounts_btn.hide()
        
        self.btn = QPushButton()
        self.btn.setIcon(QIcon(common.QTDENTER_PATH + "/imgs/identica.png"))
        self.btn.setText(self.settings["server"])
        
        self.ui.accounts_layout.addWidget(self.btn)
        
        if "timeline" in self._filters_state:
            self.ui.timeline_btn.setChecked(True)
        if "mentions" in self._filters_state:
            self.ui.mentions_btn.setChecked(True)
        if "directs" in self._filters_state:
            self.ui.directs_btn.setChecked(True)
        
        self.ui.timeline_btn.clicked.connect(self.change_filters)
        self.ui.mentions_btn.clicked.connect(self.change_filters)
        self.ui.directs_btn.clicked.connect(self.change_filters)

        # Defining list_handler instance
        self.list_handler = list_handler.List_Handler(callback=self.lists_callback)
        
        # Set some options to timeline list
        self.ui.timeline_list.setSortingEnabled(True)
        self.ui.timeline_list.sortByColumn(2, Qt.DescendingOrder)
        for column in range(2, 6):
            self.ui.timeline_list.setColumnHidden(column, True)
        self.ui.timeline_list.setColumnWidth(0, 65)
        self.ui.timeline_list.itemActivated.connect(self.reply_to_dent)
        self.ui.timeline_list.itemSelectionChanged.connect(self.change_item_read_state)
        
        # Defining list_item instance, that generates items for lists
        self.list_item = list_item.list_item()
        
        # Init notifications
        try:
            pynotify.init(sys.argv[0])
            print "Notifier loaded"
        except:
            print "Failed to init pynotify"
            
        self.show()
        
        # Initialize auther and get timelines for first time
        try:
            self.init_connector()
        except:
            print "No auth data specified"
        
        try:
            self.initialize_button_mappers()
        
            opts = {"count"     : str(self.settings["fetch_on_startup"]),
                    "name"      : self.settings["user"]
                    }
            
            if self.settings["remember_last_dent_id"] == "1":
                # Getting last dent ID from server
                temp = self.auth.get_home_timeline(opts)
                # Calculation count of dents we will download on startup
                count = temp[0]["id"] - int(self.settings["last_dent_id"])
                    
                if count == 0:
                    count = 20
                else:
                    pass
            
                opts = {"count"     : str(count),
                        "name"      : self.settings["user"]
                        }
        except:
            print "Can't specify options!"
        
        try:
            home_timeline = self.auth.get_home_timeline(opts)
            self.list_handler.add_data("home", home_timeline, self.settings["server"])
        except:
            print "Can't get home timeline. WTF?"
        
        try:
            mentions = self.auth.get_direct_messages(opts)
            self.list_handler.add_data("direct_messages", mentions, self.settings["server"])
            if self.settings["remember_last_dent_id"] == "1":
                root = self.ui.timeline_list.invisibleRootItem()
                last_item = root.child(0)
                dent_id = last_item.text(2).split(":")[0]
                self.qsettings.setValue("last_dent_id", dent_id)
            self.qsettings.sync()
        except:
            print "Can't get direct messages. WTF?"
            
        try:
            # Connect buttons
            self.connect_buttons()
        except:
            print "Failed to connect buttons!"
        
            
        # Init timer
        self.start_timer(self.settings["updateInterval"])
        
        # Init "Now Playing"
        self.np = now_playing.Now_Playing(self.settings)
        
        # Get max characters count from server
        try:
            server_data = self.auth.get_server_config("config")
            self.settings["messageLength"] = server_data["site"]["textlimit"]
        except:
            self.settings["messageLength"] = "140"