Exemple #1
0
    def ensureUniqueFilename(self, name, appendFormat="(%s)"):
        assert('%s' in appendFormat)

        info = QFileInfo(name)
        if not info.exists():
            return name

        # QDir
        dir_ = info.absoluteDir()
        # QString
        fileName = info.fileName()

        idx = 1
        while info.exists():
            file_ = fileName
            index = file_.rfind('.')
            appendString = appendFormat % idx
            if index == -1:
                file_ += appendString
            else:
                file_ = file_[:index] + appendString + file_[index:]
            info.setFile(dir_, file_)
            idx += 1

        return info.absoluteFilePath()
    def _parseTheme(self, path, name):
        '''
        @param: path QString
        @param: name QString
        @return self._Theme
        '''
        info = self._Theme()
        info.isValid = False

        if not QFile(path + 'main.css').exists() or not QFile(
                path + 'metadata.desktop').exists():
            info.isValid = False
            return info

        metadata = DesktopFile('metadata.desktop')
        info.name = metadata.name()
        info.description = metadata.comment()
        info.author = metadata.value('X-App-Author')

        # QString
        iconName = metadata.icon()
        if iconName:
            if QFileInfo.exists(path + iconName):
                info.icon = QIcon(path + iconName)
            else:
                info.icon = QIcon.fromTheme(iconName)

        licensePath = metadata.value('X-App-License')
        if licensePath and QFileInfo.exists(path + licensePath):
            info.license = gVar.appTools.readAllFileContents(path +
                                                             licensePath)

        if not info.name or name in self._themeHash:
            return info

        info.isValid = True
        self._themeHash[name] = info
        return info
Exemple #3
0
 def removeRecursively(self, filePath):
     '''
     @param: filePath QString
     '''
     fileInfo = QFileInfo(filePath)
     if not fileInfo.exists() and not fileInfo.isSymLink():
         return
     if fileInfo.isDir() and not fileInfo.isSymLink():
         dir_ = QDir(filePath)
         dir_ = dir_.canonicalPath()
         if dir_.isRoot() or dir_.path() == QDir.home().canonicalPath():
             print('CRITICAL: Attempt to remove root/home directory', dir_)
             return False
         fileNames = dir_.entryList(QDir.Files | QDir.Dirs | QDir.NoDotAndDotDot |
                 QDir.Hidden | QDir.System)
         for fileName in fileNames:
             if not self.removeRecursively(filePath + '/' + fileName):
                 return False
         if not QDir.root().rmdir(dir_.path()):
             return False
     elif not QFile.remove(filePath):
         return False
     return True
Exemple #4
0
    def _parseActions(self):  # noqa C901
        # Options
        authorsOption = QCommandLineOption(["a", "authors"])
        authorsOption.setDescription("Displays author information.")

        profileOption = QCommandLineOption(["p", "profile"])
        profileOption.setValueName("profileName")
        profileOption.setDescription("Starts with specified profile.")

        noExtensionsOption = QCommandLineOption(["e", "no-extensions"])
        noExtensionsOption.setDescription("Starts without extensions.")

        privateBrowsingOption = QCommandLineOption(["i", "private-browsing"])
        privateBrowsingOption.setDescription("Starts private browsing.")

        portableOption = QCommandLineOption(["o", "portable"])
        portableOption.setDescription("Starts in portable mode.")

        noRemoteOption = QCommandLineOption(["r", "no-remote"])
        noRemoteOption.setDescription("Starts new browser instance.")

        newTabOption = QCommandLineOption(["t", "new-tab"])
        newTabOption.setDescription("Opens new tab.")

        newWindowOption = QCommandLineOption(["w", "new-window"])
        newWindowOption.setDescription("Opens new window.")

        downloadManagerOption = QCommandLineOption(["d", "download-manager"])
        downloadManagerOption.setDescription("Opens download manager.")

        currentTabOption = QCommandLineOption(["c", "current-tab"])
        currentTabOption.setValueName("URL")
        currentTabOption.setDescription("Opens URL in current tab.")

        openWindowOption = QCommandLineOption(["u", "open-window"])
        openWindowOption.setValueName("URL")
        openWindowOption.setDescription("Opens URL in new window.")

        fullscreenOption = QCommandLineOption(["f", "fullscreen"])
        fullscreenOption.setDescription("Toggles fullscreen.")

        wmclassOption = QCommandLineOption(["wmclass", ])
        wmclassOption.setValueName("WM_CLASS")
        wmclassOption.setDescription("Application class (X11 only).")

        # Parser
        parser = QCommandLineParser()
        parser.setApplicationDescription("QtWebEngine based browser")
        # QCommandLineOption
        helpOption = parser.addHelpOption()
        # QCommandLineOption
        versionOption = parser.addVersionOption()
        parser.addOption(authorsOption)
        parser.addOption(profileOption)
        parser.addOption(noExtensionsOption)
        parser.addOption(privateBrowsingOption)
        parser.addOption(portableOption)
        parser.addOption(noRemoteOption)
        parser.addOption(newTabOption)
        parser.addOption(newWindowOption)
        parser.addOption(downloadManagerOption)
        parser.addOption(currentTabOption)
        parser.addOption(openWindowOption)
        parser.addOption(fullscreenOption)
        parser.addOption(wmclassOption)
        parser.addPositionalArgument("URL", "URLs to open", "[URL...]")

        # parse() and not process() so we can pass arbitrary options to Chromium
        parser.parse(QCoreApplication.arguments())

        if parser.isSet(helpOption):
            parser.showHelp()

        if parser.isSet(versionOption):
            parser.showVersion()

        if parser.isSet(authorsOption):
            print("David Rosca <*****@*****.**>")

            pair = self.ActionPair()
            pair.action = const.CL_ExitAction
            self._actions.append(pair)
            return

        if parser.isSet(profileOption):
            profileName = parser.value(profileOption)
            print("Falkon: Starting with profile '%s'" % profileName)

            pair = self.ActionPair()
            pair.action = const.CL_StartWithProfile
            pair.text = profileName
            self._actions.append(pair)

        if parser.isSet(noExtensionsOption):
            pair = self.ActionPair()
            pair.action = const.CL_StartWithoutAddons
            self._actions.append(pair)

        if parser.isSet(privateBrowsingOption):
            pair = self.ActionPair()
            pair.action = const.CL_StartPrivateBrowsing
            self._actions.append(pair)

        if parser.isSet(portableOption):
            pair = self.ActionPair()
            pair.action = const.CL_StartPortable
            self._actions.append(pair)

        if parser.isSet(noRemoteOption):
            pair = self.ActionPair()
            pair.action = const.CL_StartNewInstance
            self._actions.append(pair)

        if parser.isSet(newTabOption):
            pair = self.ActionPair()
            pair.action = const.CL_NewTab
            self._actions.append(pair)

        if parser.isSet(newWindowOption):
            pair = self.ActionPair()
            pair.action = const.CL_NewWindow
            self._actions.append(pair)

        if parser.isSet(downloadManagerOption):
            pair = self.ActionPair()
            pair.action = const.CL_ShowDownloadManager
            self._actions.append(pair)

        if parser.isSet(currentTabOption):
            pair = self.ActionPair()
            pair.action = const.CL_OpenUrlInCurrentTab
            pair.text = parser.value(currentTabOption)
            self._actions.append(pair)

        if parser.isSet(openWindowOption):
            pair = self.ActionPair()
            pair.action = const.CL_OpenUrlInNewWindow
            pair.text = parser.value(openWindowOption)
            self._actions.append(pair)

        if parser.isSet(fullscreenOption):
            pair = self.ActionPair()
            pair.action = const.CL_ToggleFullScreen
            self._actions.append(pair)

        if parser.isSet(wmclassOption):
            pair = self.ActionPair()
            pair.action = const.CL_WMClass
            pair.text = parser.value(wmclassOption)
            self._actions.append(pair)

        if not parser.positionalArguments():
            return

        url = parser.positionalArguments()[-1]
        fileInfo = QFileInfo(url)

        if fileInfo.exists():
            url = fileInfo.absoluteFilePath()

        if url and not url.startswith('-'):
            pair = self.ActionPair()
            pair.action = const.CL_OpenUrl
            pair.text = url
            self._actions.append(pair)