Esempio n. 1
0
 def __init__(self, parent=None):
     """
     Constructor
     
     @param parent reference to the parent widget (QWidget)
     """
     super(UserAgentsDialog, self).__init__(parent)
     self.setupUi(self)
     
     self.removeButton.clicked.connect(
         self.userAgentsTable.removeSelected)
     self.removeAllButton.clicked.connect(
         self.userAgentsTable.removeAll)
     
     self.userAgentsTable.verticalHeader().hide()
     self.__userAgentModel = UserAgentModel(
         WebBrowserWindow.userAgentsManager(), self)
     self.__proxyModel = QSortFilterProxyModel(self)
     self.__proxyModel.setSourceModel(self.__userAgentModel)
     self.searchEdit.textChanged.connect(
         self.__proxyModel.setFilterFixedString)
     self.userAgentsTable.setModel(self.__proxyModel)
     
     fm = QFontMetrics(QFont())
     height = fm.height() + fm.height() // 3
     self.userAgentsTable.verticalHeader().setDefaultSectionSize(height)
     self.userAgentsTable.verticalHeader().setMinimumSectionSize(-1)
     
     self.userAgentsTable.resizeColumnsToContents()
     self.userAgentsTable.horizontalHeader().setStretchLastSection(True)
Esempio n. 2
0
    def __initialSync(self):
        """
        Private slot to do the initial synchronization.
        """
        # Bookmarks
        if Preferences.getWebBrowser("SyncBookmarks"):
            self.__initialSyncFile(
                "bookmarks",
                WebBrowserWindow.bookmarksManager().getFileName())

        # History
        if Preferences.getWebBrowser("SyncHistory"):
            self.__initialSyncFile(
                "history",
                WebBrowserWindow.historyManager().getFileName())

        # Passwords
        if Preferences.getWebBrowser("SyncPasswords"):
            self.__initialSyncFile(
                "passwords",
                WebBrowserWindow.passwordManager().getFileName())

        # User Agent Settings
        if Preferences.getWebBrowser("SyncUserAgents"):
            self.__initialSyncFile(
                "useragents",
                WebBrowserWindow.userAgentsManager().getFileName())

        # Speed Dial Settings
        if Preferences.getWebBrowser("SyncSpeedDial"):
            self.__initialSyncFile("speeddial",
                                   WebBrowserWindow.speedDial().getFileName())

        self.__forceUpload = False
Esempio n. 3
0
 def __syncFinished(self, type_, status, download):
     """
     Private slot to handle a finished synchronization event.
     
     @param type_ type of the synchronization event (string one
         of "bookmarks", "history", "passwords", "useragents" or
         "speeddial")
     @param status flag indicating success (boolean)
     @param download flag indicating a download of a file (boolean)
     """
     if status and download:
         if type_ == "bookmarks":
             WebBrowserWindow.bookmarksManager().reload()
         elif type_ == "history":
             WebBrowserWindow.historyManager().reload()
         elif type_ == "passwords":
             WebBrowserWindow.passwordManager().reload()
         elif type_ == "useragents":
             WebBrowserWindow.userAgentsManager().reload()
         elif type_ == "speeddial":
             WebBrowserWindow.speedDial().reload()
     self.syncFinished.emit(type_, status, download)
Esempio n. 4
0
 def userAgentForUrl(cls, url):
     """
     Class method to determine the user agent for the given URL.
     
     @param url URL to determine user agent for (QUrl)
     @return user agent string (string)
     """
     agent = WebBrowserWindow.userAgentsManager().userAgentForUrl(url)
     if agent == "":
         # no agent string specified for the given host -> use global one
         agent = Preferences.getWebBrowser("UserAgent")
         if agent == "":
             # no global agent string specified -> use default one
             agent = WebBrowserWindow.webProfile().httpUserAgent()
     return agent
Esempio n. 5
0
    def __init__(self, title, url=None, parent=None):
        """
        Constructor
        
        @param title title of the menu (string)
        @param url URL to set user agent for (QUrl)
        @param parent reference to the parent widget (QWidget)
        """
        super(UserAgentMenu, self).__init__(title, parent)

        self.__manager = None
        self.__url = url
        if self.__url:
            if self.__url.isValid():
                from WebBrowser.WebBrowserWindow import WebBrowserWindow
                self.__manager = WebBrowserWindow.userAgentsManager()
            else:
                self.__url = None

        self.aboutToShow.connect(self.__populateMenu)
 def syncUserAgents(self):
     """
     Public method to synchronize the user agents.
     """
     self.__syncFile("useragents",
                     WebBrowserWindow.userAgentsManager().getFileName())
Esempio n. 7
0
    def loadSettings(self, forceUpload=False):
        """
        Public method to load the settings.
        
        @keyparam forceUpload flag indicating a forced upload of the files
            (boolean)
        """
        if self.__handler is not None:
            self.__handler.syncError.disconnect(self.__syncError)
            self.__handler.syncFinished.disconnect(self.__syncFinished)
            self.__handler.syncStatus.disconnect(self.__syncStatus)
            self.__handler.syncMessage.disconnect(self.syncMessage)
            self.__handler.shutdown()

        if self.syncEnabled():
            from . import SyncGlobals
            if (Preferences.getWebBrowser("SyncType") ==
                    SyncGlobals.SyncTypeFtp):
                from .FtpSyncHandler import FtpSyncHandler
                self.__handler = FtpSyncHandler(self)
            elif (Preferences.getWebBrowser("SyncType") ==
                  SyncGlobals.SyncTypeDirectory):
                from .DirectorySyncHandler import DirectorySyncHandler
                self.__handler = DirectorySyncHandler(self)
            self.__handler.syncError.connect(self.__syncError)
            self.__handler.syncFinished.connect(self.__syncFinished)
            self.__handler.syncStatus.connect(self.__syncStatus)
            self.__handler.syncMessage.connect(self.syncMessage)

            self.__handler.initialLoadAndCheck(forceUpload=forceUpload)

            # connect sync manager to bookmarks manager
            if Preferences.getWebBrowser("SyncBookmarks"):
                (WebBrowserWindow.bookmarksManager().bookmarksSaved.connect(
                    self.__syncBookmarks))
            else:
                try:
                    (WebBrowserWindow.bookmarksManager().bookmarksSaved.
                     disconnect(self.__syncBookmarks))
                except TypeError:
                    pass

            # connect sync manager to history manager
            if Preferences.getWebBrowser("SyncHistory"):
                (WebBrowserWindow.historyManager().historySaved.connect(
                    self.__syncHistory))
            else:
                try:
                    (WebBrowserWindow.historyManager().historySaved.disconnect(
                        self.__syncHistory))
                except TypeError:
                    pass

            # connect sync manager to passwords manager
            if Preferences.getWebBrowser("SyncPasswords"):
                (WebBrowserWindow.passwordManager().passwordsSaved.connect(
                    self.__syncPasswords))
            else:
                try:
                    (WebBrowserWindow.passwordManager().passwordsSaved.
                     disconnect(self.__syncPasswords))
                except TypeError:
                    pass

            # connect sync manager to user agent manager
            if Preferences.getWebBrowser("SyncUserAgents"):
                (WebBrowserWindow.userAgentsManager().userAgentSettingsSaved.
                 connect(self.__syncUserAgents))
            else:
                try:
                    (WebBrowserWindow.userAgentsManager().
                     userAgentSettingsSaved.disconnect(self.__syncUserAgents))
                except TypeError:
                    pass

            # connect sync manager to speed dial
            if Preferences.getWebBrowser("SyncSpeedDial"):
                (WebBrowserWindow.speedDial().speedDialSaved.connect(
                    self.__syncSpeedDial))
            else:
                try:
                    (WebBrowserWindow.speedDial().speedDialSaved.disconnect(
                        self.__syncSpeedDial))
                except TypeError:
                    pass
        else:
            self.__handler = None

            try:
                (WebBrowserWindow.bookmarksManager().bookmarksSaved.disconnect(
                    self.__syncBookmarks))
            except TypeError:
                pass
            try:
                (WebBrowserWindow.historyManager().historySaved.disconnect(
                    self.__syncHistory))
            except TypeError:
                pass
            try:
                (WebBrowserWindow.passwordManager().passwordsSaved.disconnect(
                    self.__syncPasswords))
            except TypeError:
                pass
            try:
                (WebBrowserWindow.userAgentsManager().userAgentSettingsSaved.
                 disconnect(self.__syncUserAgents))
            except TypeError:
                pass
            try:
                WebBrowserWindow.speedDial().speedDialSaved.disconnect(
                    self.__syncSpeedDial)
            except TypeError:
                pass