Ejemplo n.º 1
0
    def updateFileTags(self, filename, post, skip=False):
        res = self.getResource(filename)

        if skip and res.hasProperty(Soprano.Vocabulary.NAO.personalIdentifier()):
            return

        #remove all current tags
        res.removeProperty(res.tagUri())
        #res.removeProperty(Soprano.Vocabulary.NAO.isRelated())
        #res.removeProperty(Soprano.Vocabulary.NAO.rating())
        #res.removeProperty(Soprano.Vocabulary.NAO.contributor())
        #res.removeProperty(Soprano.Vocabulary.NAO.personalIdentifier())

        for tag in post.tags:
            self._addTag(res, tag.name)
        url = KUrl(post.board_url)
        url_res = Nepomuk.Resource(url)
        url_res.addType(Nepomuk.Vocabulary.NFO.Website())
        url_res.setLabel(url.prettyUrl())
        res.addIsRelated(url_res)

        if post.source:
            res.setDescription("Source: %s" % KUrl(post.source).prettyUrl())

        if post.score:
            res.addProperty(Soprano.Vocabulary.NAO.rating(), Nepomuk.Variant(post.score))

        if post.author:
            res.addProperty(Soprano.Vocabulary.NAO.contributor(), Nepomuk.Variant(post.author))

        if post.rating:
            self._addTag(res, "rating-%s" % post.rating)

        res.addProperty(Soprano.Vocabulary.NAO.personalIdentifier(), Nepomuk.Variant(str(post.id)))
Ejemplo n.º 2
0
def tryOpen():
    view = kate.activeView()
    assert('View expected to be valid' and view is not None)
    assert('This action supposed to select some text before' and view.selection())

    doc = view.document()
    doc_url = doc.url()
    new_url = KUrl(_try_make_url_from_text(view.selectionText()))

    kate.kDebug('Current document URI: {}'.format(repr(doc_url)))

    # 0) Make sure it is valid
    if not new_url.isValid():
        kate.ui.popup(
            i18nc('@title:window', 'Error')
          , i18nc('@info:tooltip', "Selected text doesn't looks like a valid URI")
          , 'dialog-error'
          )
        return

    # 1) Is it have some schema? and current document is not 'Untitled'...
    if new_url.isRelative() and not doc_url.isEmpty():
        # Replace filename from the doc_url w/ the current selection
        new_url = doc_url.upUrl()
        new_url.addPath(view.selectionText())

    kate.kDebug('Trying URI: {}'.format(repr(new_url)))
    # Ok, try to open it finally
    _try_open_show_error(new_url)
Ejemplo n.º 3
0
    def batch_download(self, ok):

        "Download images in batch."

        selected_items = self.thumbnailarea.selected_images()

        if not selected_items:
            return

        start_url = KUrl("kfiledialog:///danbooru")
        caption = i18n("Select a directory to save the images to")
        directory = KFileDialog.getExistingDirectoryUrl(start_url, self,
                                                        caption)

        if directory.isEmpty():
            return

        for item in selected_items:

            file_url = item.url_label.url()
            tags = item.data.tags

            # Make a local copy to append paths as addPath works in-place
            destination = KUrl(directory)

            file_name = KUrl(file_url).fileName()
            destination.addPath(file_name)

            job = KIO.file_copy(KUrl(file_url), destination, -1)
            job.setProperty("tags", QVariant(tags))
            job.result.connect(self.batch_download_slot)
Ejemplo n.º 4
0
	def intercept_link(self, url):
		"""Allows to open documents or scrolling to anchors when clicking links"""
		#reenable scrolling to anchor in document
		if url.hasFragment() and url.scheme() == 'about' and url.path() == 'blank':
			self.preview.page().currentFrame().scrollToAnchor(url.fragment())
		elif url.isRelative() and self.queryExit():
			#TODO: less hacky, extensions
			url = KUrl(self.editor.document().url().path() + url.path())
			self.editor.document().openUrl(url)
		else:
			QDesktopServices.openUrl(url)
Ejemplo n.º 5
0
 def findDocument(self, url):
     """ Return the opened document or False. """
     if not isinstance(url, KUrl):
         url = KUrl(url)
     # we use string comparison, because sometimes percent encoding
     # issues make the same QUrls look different, esp when dragged
     # from KMail...
     url = url.toString()
     for d in self.documents:
         if d.url().toString() == url:
             return d
     return False
Ejemplo n.º 6
0
    def kioFiles(self, itemlist):
        if type(itemlist) != list:
            urlList = []
            for item in itemlist:
                urlList.append(dict(url=item.url().url(), isDir=item.isDir()))
            self.cache[self.cacheUrl] = urlList

        urls = []

        for ifile in itemlist:
            if type(ifile) == dict:
                url = KUrl(ifile["url"])
                isDir = ifile["isDir"]
            else:
                url = ifile.url()
                isDir = ifile.isDir()

            path = url.url()
            if isDir and not path.endswith("/"):
                path += "/"

            if self.includeFilters:
                matched = False
                i = 0
                while not matched and i < len(self.includeFilters):
                    if self.includeFilters[i].search(path):
                        matched = True
                    i += 1
                if not matched:
                    continue

            if self.excludeFilters:
                matched = False
                for excludeFilter in self.excludeFilters:
                    if excludeFilter.search(path):
                        matched = True
                        break
                if matched:
                    continue

            if isDir:
                if self.recursion < self.maxRecursion:
                    self.dirStack.append((self.recursion + 1, url))
            else:
                mime = KMimeType.findByUrl(url)[0]
                if self.validMime(mime):
                    urls.append(url)

        urls = sorted(urls, lambda a, b: -1 if len(a.url()) < len(b.url()) else 1)

        for url in urls:
            self.fileFound.emit(url)
 def __kdeGetSaveFileName(parent = None, caption = QString(), dir_ = QString(),
                          filter = QString(), selectedFilter = None, 
                          options = QFileDialog.Options()):
     """
     Module function to get the name of a file for saving it.
     
     @param parent parent widget of the dialog (QWidget)
     @param caption window title of the dialog (QString)
     @param dir_ working directory of the dialog (QString)
     @param filter filter string for the dialog (QString)
     @param selectedFilter selected filter for the dialog (QString)
     @param options various options for the dialog (QFileDialog.Options)
     @return name of file to be saved (QString)
     """
     if not QString(filter).isEmpty():
         filter = __convertFilter(filter, selectedFilter)
     wdir = __workingDirectory(dir_)
     dlg = KFileDialog(KUrl.fromPath(wdir), filter, parent)
     if wdir != dir_:
         dlg.setSelection(dir_)
     dlg.setOperationMode(KFileDialog.Saving)
     dlg.setMode(KFile.Modes(KFile.File) | KFile.Modes(KFile.LocalOnly))
     dlg.setWindowTitle(caption.isEmpty() and \
         QApplication.translate('KFileDialog', 'Save As') or caption)
     
     dlg.exec_()
     
     if selectedFilter is not None:
         flt = dlg.currentFilter()
         flt.prepend("(").append(")")
         selectedFilter.replace(0, selectedFilter.length(), flt)
     
     return dlg.selectedFile()
Ejemplo n.º 8
0
    def init(self):
        self.setHasConfigurationInterface(False)
        self.setAspectRatioMode(Plasma.Square)
        self.resize(300,400)     
        
        self.layout = QGraphicsLinearLayout(Qt.Vertical, self.applet)
        
        self.label = Plasma.Label(self.applet)
        self.label.setText("Enter the text to be converted")
        self.label.nativeWidget().setAlignment(Qt.AlignHCenter)
        self.layout.addItem(self.label)
        
        self.text = Plasma.LineEdit(self.applet)
        self.text.setClearButtonShown(True)
        self.text.nativeWidget().setMaxLength(1000)
        self.layout.addItem(self.text)
        
        self.button = Plasma.PushButton(self.applet)
        self.button.setText("Generate")
        self.button.clicked.connect(self.generate)
        self.layout.addItem(self.button)
        
        self.webView = Plasma.WebView(self.applet)
        self.webView.setUrl(KUrl("about:blank"))
	self.webView.setMinimumSize(250, 250)
        self.layout.addItem(self.webView)
        self.setLayout(self.layout)
Ejemplo n.º 9
0
def get_linter(linter_name, callback):
    """tries to retrieve a linter and calls `callback` on it on success"""
    if linter_name in LINTERS:
        callback(LINTERS[linter_name])
        return

    if linter_name not in NEEDS_LICENSE:
        showError(i18nc('@info:status', 'No acceptable linter named %1!', linter_name))
        return

    license, objname, url = NEEDS_LICENSE[linter_name]
    cache_path = p.join(CACHE_DIR, linter_name + '.js')

    def success():
        """store newly created linter and “return” it"""
        LINTERS[linter_name] = JSModule(JS_ENGINE, cache_path, objname)
        callback(LINTERS[linter_name])

    if p.exists(cache_path):
        success()
        return

    # the user doesn’t have the file. ask to accept its license
    if not license_accepted(license):
        return

    download = KIO.file_copy(KUrl(url), KUrl.fromPath(cache_path))
    @download.result.connect
    def _call(job):
        if job.error():
            showError(i18nc('@info:status', 'Download failed'))
        else:
            success()
    download.start()
Ejemplo n.º 10
0
def tag_danbooru_item(filename, tags, blacklist=None, board_url=None):

    """Tag a file using a specific :class:`DanbooruItem` tags."""

    resource_manager = Nepomuk.ResourceManager.instance()

    if not resource_manager.initialized():
        # Nepomuk not running - bail out
        return

    absolute_path = QtCore.QFileInfo(filename).absoluteFilePath()
    resource = Nepomuk.File(KUrl(absolute_path))

    for tag in tags:

        if blacklist is not None and tag in blacklist:
            continue

        nepomuk_tag = Nepomuk.Tag(tag)
        nepomuk_tag.setLabel(tag)
        resource.addTag(nepomuk_tag)


    if board_url is not None:
        website_resource = Nepomuk.Resource(board_url)
        website_resource.addType(Nepomuk.Vocabulary.NFO.Website())
        website_resource.setLabel(board_url.prettyUrl())
        resource.setDescription(
                    i18n("Retrieved from %1").arg(board_url.prettyUrl()))
        resource.addIsRelated(website_resource)
Ejemplo n.º 11
0
 def openDirectory(self, path=None):
     """
     Opens a folder. If None, opes the document folder if any, or else
     the current working directory in the default KDE file manager.
     """
     if path is None:
         d = self.mainwin.currentDocument()
         if d.url().isEmpty():
             if d.localFileManager():
                 path = d.localFileManager().directory
             else:
                 path = self.mainwin.app.defaultDirectory() or os.getcwd()
         else:
             path = d.url().resolved(KUrl('.'))
     url = KUrl(path)
     url.adjustPath(KUrl.RemoveTrailingSlash)
     sip.transferto(KRun(url, self.mainwin), None) # C++ will delete it
Ejemplo n.º 12
0
 def initialize(self):
     " Init Class dock "
     self.dock = QDockWidget()
     self.dock.setFeatures(QDockWidget.DockWidgetFloatable
                           | QDockWidget.DockWidgetMovable)
     self.dock.setWindowTitle(__doc__)
     self.dock.setStyleSheet('QDockWidget::title{text-align: center;}')
     self.boton = QAction(QIcon.fromTheme("list-add"), 'Open', self)
     self.saver = QAction(QIcon.fromTheme("document-save"), 'Save', self)
     self.apiss = QAction(QIcon.fromTheme("help"), 'Python API Help', self)
     QToolBar(self.dock).addActions((self.boton, self.saver, self.apiss))
     try:
         self.factory = KPluginLoader("kigpart").factory()
         self.part = self.factory.create(self)
         self.part.setReadWrite(True)
         self.boton.triggered.connect(lambda: self.part.openUrl(
             KUrl(
                 str(
                     QFileDialog.getOpenFileName(
                         self.dock, ' Open Geometry Plot ',
                         path.expanduser("~"), ';;'.join([
                             '(*.{})'.format(e)
                             for e in ['fig', 'kig', 'kigz', 'seg', 'fgeo']
                         ]))))))
         self.saver.triggered.connect(lambda: self.part.saveAs(
             KUrl(
                 str(
                     QFileDialog.getSaveFileName(
                         self.dock, ' Save Geometry Plot ',
                         path.expanduser("~"), ';;'.join([
                             '(*.{})'.format(e)
                             for e in ['kig', 'kigz', 'fig']
                         ]))))))
         self.apiss.triggered.connect(lambda: open_new_tab(
             'http://edu.kde.org/kig/manual/scripting-api/classObject.html')
                                      )
         self.dock.setWidget(self.part.widget())
     except:
         self.dock.setWidget(
             QLabel(""" <center> <h3>ಠ_ಠ<br>
         ERROR: Please, install KIG and PyKDE ! </h3><br>
         <br><i> (Sorry, cant embed non-Qt Apps). </i><center>"""))
     self.misc = self.locator.get_service('misc')
     self.misc.add_widget(self.dock,
                          QIcon.fromTheme("accessories-calculator"),
                          __doc__)
Ejemplo n.º 13
0
    def batch_download(self, ok):

        "Download images in batch."

        selected_items = self.thumbnailarea.selected_images()

        if not selected_items:
            return

        start_url = KUrl("kfiledialog:///danbooru")
        caption = i18n("Select a directory to save the images to")
        directory = KFileDialog.getExistingDirectoryUrl(
            start_url, self, caption)

        if directory.isEmpty():
            return

        for item in selected_items:

            file_url = item.url_label.url()
            tags = item.data.tags

            # Make a local copy to append paths as addPath works in-place
            destination = KUrl(directory)

            file_name = KUrl(file_url).fileName()
            destination.addPath(file_name)

            job = KIO.file_copy(KUrl(file_url), destination, -1)
            job.setProperty("tags", QVariant(tags))
            job.result.connect(self.batch_download_slot)
Ejemplo n.º 14
0
	def __init__(self, frame, locationBar, dirView, logEdit, siteButton):

		QObject.__init__(self)

		self.frame = frame
		self.dirView = dirView
		self.locationBar = locationBar
		self.logEdit = logEdit
		self.siteButton = siteButton

		self.settingsWidget = SettingsWidget(self.frame)
		self.settingsWidget.setVisible(False)

		self.progressWidget = ProgressWidget(self.frame)
		self.progressWidget.setVisible(False)

		self.dirModel = DirModel()
		self.dirView.setModel(self.dirModel)

		# enable sorting

		self.connect(self.dirView.header(), SIGNAL("sectionClicked(int)"), self.dirView.sortByColumn)

		# set filename & ascending to default

		self.dirView.header().setSortIndicator(DirModel.FILENAME, Qt.AscendingOrder)

		self.connect(self.locationBar, SIGNAL("returnPressed()"), self.slotReturnPressed)
		self.connect(self.dirView, SIGNAL("doubleClicked(const QModelIndex&)"), self.slotDoubleClicked)
		self.connect(self.siteButton, SIGNAL("clicked()"), self.slotSiteClicked)
		self.connect(self.locationBar.configureButton, SIGNAL("clicked()"), self.slotConfigureButtonClicked)

		# connect drop signal

		self.connect(self.dirView, SIGNAL("drop(QByteArray*)"), self.slotDrop)

		# default to home directory

		kurl = KUrl()
		kurl.setProtocol("file");
		kurl.setPath(QDir.homePath());
		
		self.attemptKurl = kurl;
		self.listDir(self.attemptKurl);
Ejemplo n.º 15
0
 def item(icon, fileName):
     """ Add item to the fileList list widget. """
     directory, name = os.path.split(fileName)
     if directory != basedir:
         name += " ({0})".format(os.path.normpath(directory))
     i = QListWidgetItem(KIcon(icon), name, fileList)
     i.setFlags(Qt.ItemIsEnabled | Qt.ItemIsSelectable | Qt.ItemIsUserCheckable)
     i.ext = os.path.splitext(fileName)[1]
     i.url = KUrl.fromPath(fileName).url()
     i.setCheckState(Qt.Checked if i.ext in exts else Qt.Unchecked)
Ejemplo n.º 16
0
 def add_file_source_dialog(self):
     filename = ''
     filter = QString('*.iso|' + _('ISO Files') + '\n*.img|' + _('IMG Files'))
     # FIXME: should set the default path KUrl to users home dir...
     # This is all screwy as its run as root under kdesudo... Home = root and not user.. blarg!
     # Need to convert to plain string for backend to work
     filename = str(KFileDialog.getOpenFileName(KUrl(),filter))
     if not filename:
       return
     self.__backend.add_file_source(filename)
Ejemplo n.º 17
0
	def slotTransfer(self, session, fileName, source):
	
		dstSession = (self.session, self.session_2)[(session != self.session) ^ source]
		srcSession = (self.session_2, self.session)[(session != self.session) ^ source]

		srcKurl = KUrl(srcSession.kurl)
		srcKurl.addPath(fileName)

		dstKurl = KUrl(dstSession.kurl)
		dstKurl.addPath(fileName)

		print "transfer " + srcKurl.prettyUrl() + " to " + dstKurl.prettyUrl()

		session.copyFile(srcKurl, dstKurl)
Ejemplo n.º 18
0
 def openUrl(self, url, encoding=None):
     if not isinstance(url, KUrl):
         url = KUrl(url)
     # If no encoding given, set default or check if we can remember it
     if not encoding:
         encoding = self.defaultEncoding
         if self.keepMetaInfo() and not url.isEmpty():
             group = self.stateManager().groupForUrl(url)
             if group:
                 encoding = group.readEntry("encoding", "")
     # If there is only one document open and it is empty, nameless and
     # unmodified, use it.
     if (not url.isEmpty()
         and len(self.documents) == 1
         and not self.documents[0].isModified()
         and self.documents[0].url().isEmpty()):
         d = self.documents[0]
         d.openUrl(url, encoding)
     else:
         d = (not url.isEmpty() and self.findDocument(url)
              or self.createDocument(url, encoding))
     return d
Ejemplo n.º 19
0
    def changePage(self, url, args):
        myurl = str(KUrl(url).prettyUrl().toUtf8())
        #if it is an external link, we feed id directly to KHTMLpart
        #it it is not, we do a workaround to inject our headers
        if myurl.find("http://" + config.language + "." + config.project +
                      ".org/") == -1:
            self.visor.openUrl(KUrl(url))
        else:
            headers = {
                'User-Agent': config.useragent,
                'Cookie': self.dv.lm.cookies()
            }
        #convert relative links to absolute
        if myurl[0:8] == "file:///":
            myurl = "href=\"http://" + config.language + "." + config.project + ".org/" + myurl[
                7:]
        try:
            response = urllib2.urlopen(urllib2.Request(myurl, None, headers))
            html = response.read()
            html = re_local.sub(
                "href=\"http://" + config.language + "." + config.project +
                ".org/", html)
            html = re_local1.sub(
                "href='http://" + config.language + "." + config.project +
                ".org/", html)

            html = re_src.sub(
                "src=\"http://" + config.language + "." + config.project +
                ".org/", html)
            html = re_action.sub(
                "action=\"http://" + config.language + "." + config.project +
                ".org/", html)
            self.visor.begin()
            self.visor.write(html)
            self.visor.end()
        except:
            self.writeMsgBox("Unable to open link")
Ejemplo n.º 20
0
    def slotFileDialog(self):
        """
            Get file name from file dialog
        """

        if ctx.Pds.session == ctx.pds.Kde4:
            from PyKDE4.kio import KFileDialog
            from PyKDE4.kdecore import KUrl
            url=KUrl.fromPath("/boot/")
            filename=unicode(KFileDialog.getOpenFileName(url, "", self, i18n("File System")))
        else:
            filename=unicode(QtGui.QFileDialog.getOpenFileName(self, i18n("File System"), "/boot/"))

        if filename:
            self.setFile(filename)
Ejemplo n.º 21
0
    def slotFileDialog(self):
        """
            Get file name from file dialog
        """

        if ctx.Pds.session == ctx.pds.Kde4:
            from PyKDE4.kio import KFileDialog
            from PyKDE4.kdecore import KUrl
            url=KUrl.fromPath("/boot/")
            filename=unicode(KFileDialog.getOpenFileName(url, "", self, i18n("File System")))
        else:
            filename=unicode(QtGui.QFileDialog.getOpenFileName(self, i18n("File System"), "/boot/"))

        if filename:
            self.setFile(filename)
Ejemplo n.º 22
0
    def list(self):
        url = kate.activeDocument().url()
        self.project = self.getProjectUrl(url)

        for doc in kate.documentManager.documents():
            self.addFileUrl(doc.url(), "Open document")

        if self.project:
            self.reason = "In project %s" % self.project
            self.rootPath = KUrl(self.project)
        else:
            self.reason = "Same path of %s" % url.fileName()
            self.rootPath = url.upUrl()

        self.lister.list(self.rootPath, recurse=self.project != False)
Ejemplo n.º 23
0
def openFile(fileName, window, cmd = None):
    """
    Opens a file with command cmd (string, read from config)
    or with the KDE default application (via KRun).
    """
    if cmd:
        cmd, err = KShell.splitArgs(cmd)
        if err == KShell.NoError:
            cmd.append(fileName)
            try:
                Popen(cmd)
                return
            except OSError:
                pass
    # let C++ own the KRun object, it will delete itself.
    sip.transferto(KRun(KUrl.fromPath(fileName), window), None)
 def add_key_clicked(self):
   """Provide a file chooser that allows to add the gnupg of a trusted
      software vendor"""
   home = QDir.homePath()
   if "SUDO_USER" in os.environ:
       home = os.path.expanduser("~%s" % os.environ["SUDO_USER"])
   url = KUrl.fromPath(home)
   filename = KFileDialog.getOpenFileName(url, 'application/pgp-keys', self.userinterface, utf8(_("Import key")))
   if filename:
     if not self.add_key(filename):
       title = _("Error importing selected file")
       text = _("The selected file may not be a GPG key file " \
               "or it might be corrupt.")
       KMessageBox.sorry(self.userinterface,
             utf8(text),
             utf8(title))
     self.show_keys()
Ejemplo n.º 25
0
	def slotDoubleClicked(self, index):

		print "doubleClicked"

		fileName = self.dirModel.getField(index.row(), DirModel.FILENAME)

		if self.dirModel.getField(index.row(), DirModel.DIRECTORY) == True:

			# attempt to change the dir

			self.attemptKurl = KUrl(self.kurl)
			self.attemptKurl.addPath(fileName)
			self.attemptKurl.cleanPath()

			# print self.attemptKurl
	
			self.listDir(self.attemptKurl)
		else:

			self.emit(SIGNAL("transfer(PyQt_PyObject, QString, bool)"), self, fileName, True)
Ejemplo n.º 26
0
 def __kdeGetExistingDirectory(parent = None, caption = QString(), 
                         dir_ = QString(), 
                         options = QFileDialog.Options(QFileDialog.ShowDirsOnly)):
     """
     Module function to get the name of a directory.
     
     @param parent parent widget of the dialog (QWidget)
     @param caption window title of the dialog (QString)
     @param dir_ working directory of the dialog (QString)
     @param options various options for the dialog (QFileDialog.Options)
     @return name of selected directory (QString)
     """
     wdir = __workingDirectory(dir_)
     dlg = KFileDialog(KUrl.fromPath(wdir), QString(), parent)
     dlg.setOperationMode(KFileDialog.Opening)
     dlg.setMode(KFile.Modes(KFile.Directory) | KFile.Modes(KFile.LocalOnly) | \
                 KFile.Modes(KFile.ExistingOnly))
     dlg.setWindowTitle(caption.isEmpty() and \
         QApplication.translate('KFileDialog', 'Select Directory') or caption)
     
     dlg.exec_()
     
     return dlg.selectedFile()
Ejemplo n.º 27
0
 def openPDF(self, fileName):
     if self.part:
         if self.part.openUrl(KUrl.fromPath(fileName)):
             self.setCurrentWidget(self.part.widget())
     else:
         openPDF(fileName, self.window())
Ejemplo n.º 28
0
class Session (QObject):

	def __init__(self, frame, locationBar, dirView, logEdit, siteButton):

		QObject.__init__(self)

		self.frame = frame
		self.dirView = dirView
		self.locationBar = locationBar
		self.logEdit = logEdit
		self.siteButton = siteButton

		self.settingsWidget = SettingsWidget(self.frame)
		self.settingsWidget.setVisible(False)

		self.progressWidget = ProgressWidget(self.frame)
		self.progressWidget.setVisible(False)

		self.dirModel = DirModel()
		self.dirView.setModel(self.dirModel)

		# enable sorting

		self.connect(self.dirView.header(), SIGNAL("sectionClicked(int)"), self.dirView.sortByColumn)

		# set filename & ascending to default

		self.dirView.header().setSortIndicator(DirModel.FILENAME, Qt.AscendingOrder)

		self.connect(self.locationBar, SIGNAL("returnPressed()"), self.slotReturnPressed)
		self.connect(self.dirView, SIGNAL("doubleClicked(const QModelIndex&)"), self.slotDoubleClicked)
		self.connect(self.siteButton, SIGNAL("clicked()"), self.slotSiteClicked)
		self.connect(self.locationBar.configureButton, SIGNAL("clicked()"), self.slotConfigureButtonClicked)

		# connect drop signal

		self.connect(self.dirView, SIGNAL("drop(QByteArray*)"), self.slotDrop)

		# default to home directory

		kurl = KUrl()
		kurl.setProtocol("file");
		kurl.setPath(QDir.homePath());
		
		self.attemptKurl = kurl;
		self.listDir(self.attemptKurl);

	def slotDrop(self, encodedData):
		
		stream = QDataStream(encodedData, QIODevice.ReadOnly)

		fileInfoList = list()

		while stream.atEnd() == False:

			fileInfos = QVariant()
			stream >> fileInfos
			fileInfoList.append(fileInfos)

		self.emit(SIGNAL("transfer(PyQt_PyObject, QString, bool)"), self, fileInfoList[0].toList()[DirModel.FILENAME].toString(), False)

		# TODO: queue rest

		#print "filename: " + fileInfos.toList()[DirModel.FILENAME].toString() + " directory: " + str(fileInfos.toList()[DirModel.DIRECTORY].toBool()) + " link: " + str(fileInfos.toList()[DirModel.LINK].toBool())

	def slotConfigureButtonClicked(self):
		if self.settingsWidget.isHidden():
			self.settingsWidget.show()
		else:
			self.settingsWidget.hide()

	def slotReturnPressed(self):

		kurl = KUrl()
		if (self.locationBar.getUrlString() != None):
			kurl.setProtocol("ftps")
			kurl.setHost(self.locationBar.getUrlString())
		else:
			kurl.setProtocol("file")
		kurl.setUser(self.settingsWidget.userEdit.text())
		kurl.setPass(self.settingsWidget.passEdit.text())
		kurl.setPort(int(self.settingsWidget.portEdit.text()))
		kurl.addPath(self.locationBar.getPathString())
		kurl.cleanPath()

		self.attemptKurl = kurl

		# print self.attemptKurl

		self.listDir(self.attemptKurl)

	def slotResult(self, job):

		print "result"
		if job.error():
			KMessageBox.sorry(None, job.errorString())
			if self.progressWidget.isVisible():
				self.progressWidget.hide()

		self.frame.setEnabled(True)

	def slotEntries(self, job, entries):

		print "entries"

		self.dirModel.list = []

		for entry in entries:

			# the last to entries do not appear as columns in dirview

			variantList = [
				entry.stringValue(KIO.UDSEntry.UDS_NAME),
				entry.stringValue(KIO.UDSEntry.UDS_USER),
				entry.stringValue(KIO.UDSEntry.UDS_GROUP),
				entry.numberValue(KIO.UDSEntry.UDS_SIZE),
				entry.isDir(),
				entry.isLink()
			]

			modelIndex = self.dirModel.createIndex(self.dirModel.rowCount(), 0)

			if (entry.stringValue(KIO.UDSEntry.UDS_NAME) != "."):
				self.dirModel.setData(modelIndex, QVariant(variantList))

		self.dirView.sortByColumn(self.dirView.header().sortIndicatorSection(), self.dirView.header().sortIndicatorOrder())

		self.kurl = self.attemptKurl
		self.locationBar.setKurl(self.kurl)

	def slotDoubleClicked(self, index):

		print "doubleClicked"

		fileName = self.dirModel.getField(index.row(), DirModel.FILENAME)

		if self.dirModel.getField(index.row(), DirModel.DIRECTORY) == True:

			# attempt to change the dir

			self.attemptKurl = KUrl(self.kurl)
			self.attemptKurl.addPath(fileName)
			self.attemptKurl.cleanPath()

			# print self.attemptKurl
	
			self.listDir(self.attemptKurl)
		else:

			self.emit(SIGNAL("transfer(PyQt_PyObject, QString, bool)"), self, fileName, True)

	def slotSiteClicked(self):
		
		if self.kurl == "":
			return

		specialJob = KIO.special(self.kurl, "SITE HELP", KIO.HideProgressInfo)
		self.doJobDefaults(specialJob)

	def slotData(self, job, bytearray):

		print bytearray

	def slotInfoMessage(self, job, plain, rich):

		self.logEdit.appendPlainText(plain)
		#print plain

	def slotPercent(self, job, percent):

		self.progressWidget.setPercent(percent)

	def doJobDefaults(self, job):
		
		job.addMetaData("kasablanca-logging", "true")
		if self.settingsWidget.tlsCheck.isChecked():
			job.addMetaData("kasablanca-tls", "true")
			job.addMetaData("kasablanca-tls-data", "true")
		else:
			job.addMetaData("kasablanca-tls", "false")
			job.addMetaData("kasablanca-tls-data", "false")
		self.connect(job, SIGNAL("result (KJob *)"), self.slotResult)
		self.connect(job, SIGNAL("infoMessage(KJob*, const QString&, const QString&)"), self.slotInfoMessage) 

		self.frame.setEnabled(False)

	def copyFile(self, srcKurl, dstKurl):
		
		copyJob = KIO.copy(srcKurl, dstKurl, KIO.HideProgressInfo)
		self.doJobDefaults(copyJob)
		self.connect(copyJob, SIGNAL("percent(KJob*, unsigned long)"), self.slotPercent)	
		self.progressWidget.show()

	def listDir(self, kurl):

		listJob = KIO.listDir(kurl, KIO.HideProgressInfo)
		self.doJobDefaults(listJob)
		self.connect(listJob, SIGNAL("entries (KIO::Job *, const KIO::UDSEntryList&)"), self.slotEntries)
Ejemplo n.º 29
0
	def slotReturnPressed(self):

		kurl = KUrl()
		if (self.locationBar.getUrlString() != None):
			kurl.setProtocol("ftps")
			kurl.setHost(self.locationBar.getUrlString())
		else:
			kurl.setProtocol("file")
		kurl.setUser(self.settingsWidget.userEdit.text())
		kurl.setPass(self.settingsWidget.passEdit.text())
		kurl.setPort(int(self.settingsWidget.portEdit.text()))
		kurl.addPath(self.locationBar.getPathString())
		kurl.cleanPath()

		self.attemptKurl = kurl

		# print self.attemptKurl

		self.listDir(self.attemptKurl)
Ejemplo n.º 30
0
    def setupUi(self):
        apply(KParts.MainWindow.__init__, (self, ))
        self.resize(
            QtCore.QSize(QtCore.QRect(0, 0, 1150, 671).size()).expandedTo(
                self.minimumSizeHint()))

        #self.setMinimumSize(QtCore.QSize(1100,671))
        self.setSizePolicy(QtGui.QSizePolicy.Expanding,
                           QtGui.QSizePolicy.Expanding)

        self.centralwidget = QtGui.QWidget(self)
        self.centralwidget.setObjectName("centralwidget")
        self.centralwidget.setSizePolicy(QtGui.QSizePolicy.Expanding,
                                         QtGui.QSizePolicy.Expanding)
        #self.centralwidget.setGeometry(QtCore.QRect(0,0,1150,72))

        self.setObjectName("mainwindow")

        self.horizontalLayoutWidget = QtGui.QWidget(self.centralwidget)
        self.horizontalLayoutWidget.setGeometry(QtCore.QRect(0, 0, 1094, 72))
        self.horizontalLayoutWidget.setObjectName("horizontalLayoutWidget")

        self.hboxlayout = QtGui.QHBoxLayout(self.horizontalLayoutWidget)
        self.hboxlayout.setContentsMargins(5, -1, 5, -1)
        self.hboxlayout.setObjectName("hboxlayout")

        self.TB_diff_revert_warn = QtGui.QToolButton(
            self.horizontalLayoutWidget)
        self.TB_diff_revert_warn.setMinimumSize(QtCore.QSize(55, 55))
        self.TB_diff_revert_warn.setMaximumSize(QtCore.QSize(55, 55))
        self.TB_diff_revert_warn.setIcon(
            QtGui.QIcon("Resources/icons/bw-diff-revert-warn.png"))
        self.TB_diff_revert_warn.setIconSize(QSize(55, 55))
        self.TB_diff_revert_warn.setObjectName("TB_diff_revert_warn")
        self.hboxlayout.addWidget(self.TB_diff_revert_warn)

        self.TB_diff_next = QtGui.QToolButton(self.horizontalLayoutWidget)
        self.TB_diff_next.setMinimumSize(QtCore.QSize(55, 55))
        self.TB_diff_next.setIcon(QtGui.QIcon("Resources/icons/diff-next.png"))
        self.TB_diff_next.setIconSize(QSize(55, 55))
        self.TB_diff_next.setObjectName("diff_next")
        self.hboxlayout.addWidget(self.TB_diff_next)

        self.line = QtGui.QFrame(self.horizontalLayoutWidget)
        self.line.setFrameShape(QtGui.QFrame.VLine)
        self.line.setFrameShadow(QtGui.QFrame.Sunken)
        self.line.setObjectName("line")
        self.hboxlayout.addWidget(self.line)

        self.TB_user_whitelist = QtGui.QToolButton(self.horizontalLayoutWidget)
        self.TB_user_whitelist.setMinimumSize(QtCore.QSize(55, 55))
        self.TB_user_whitelist.setIcon(
            QtGui.QIcon("Resources/icons/user-whitelist.png"))
        self.TB_user_whitelist.setIconSize(QSize(55, 55))
        self.TB_user_whitelist.setObjectName("TB_user_whitelist")
        self.hboxlayout.addWidget(self.TB_user_whitelist)

        self.TB_diff_revert = QtGui.QToolButton(self.horizontalLayoutWidget)
        self.TB_diff_revert.setMinimumSize(QtCore.QSize(55, 55))
        self.TB_diff_revert.setIconSize(QSize(55, 55))
        self.TB_diff_revert.setIcon(
            QtGui.QIcon("Resources/icons/diff-revert.png"))
        self.TB_diff_revert.setObjectName("TB_diff_revert")
        self.hboxlayout.addWidget(self.TB_diff_revert)

        self.TB_user_template = QtGui.QToolButton(self.horizontalLayoutWidget)
        self.TB_user_template.setMinimumSize(QtCore.QSize(55, 55))
        self.TB_user_template.setIconSize(QSize(55, 55))
        self.TB_user_template.setIcon(
            QtGui.QIcon("Resources/icons/bw-user-template.png"))
        self.TB_user_template.setObjectName("TB_user_template")
        self.hboxlayout.addWidget(self.TB_user_template)

        self.TB_user_warn = QtGui.QToolButton(self.horizontalLayoutWidget)
        self.TB_user_warn.setMinimumSize(QtCore.QSize(55, 55))
        self.TB_user_warn.setIconSize(QSize(55, 55))
        self.TB_user_warn.setIcon(
            QtGui.QIcon("Resources/icons/bw-user-warn.png"))
        self.TB_user_warn.setObjectName("TB_user_warn")
        self.hboxlayout.addWidget(self.TB_user_warn)

        self.line_2 = QtGui.QFrame(self.horizontalLayoutWidget)
        self.line_2.setFrameShape(QtGui.QFrame.VLine)
        self.line_2.setFrameShadow(QtGui.QFrame.Sunken)
        self.line_2.setObjectName("line_2")
        self.hboxlayout.addWidget(self.line_2)

        self.TB_cancel_all = QtGui.QToolButton(self.horizontalLayoutWidget)
        self.TB_cancel_all.setMinimumSize(QtCore.QSize(55, 55))
        self.TB_cancel_all.setIconSize(QSize(55, 55))
        self.TB_cancel_all.setIcon(
            QtGui.QIcon("Resources/icons/bw-cancel-all.png"))
        self.TB_cancel_all.setObjectName("TB_cancel_all")
        self.hboxlayout.addWidget(self.TB_cancel_all)

        self.TB_undo = QtGui.QToolButton(self.horizontalLayoutWidget)
        self.TB_undo.setMinimumSize(QtCore.QSize(55, 55))
        self.TB_undo.setIconSize(QSize(55, 55))
        self.TB_undo.setIcon(QtGui.QIcon("Resources/icons/bw-undo.png"))
        self.TB_undo.setObjectName("TB_undo")
        self.hboxlayout.addWidget(self.TB_undo)

        self.line_8 = QtGui.QFrame(self.horizontalLayoutWidget)
        self.line_8.setFrameShape(QtGui.QFrame.VLine)
        self.line_8.setFrameShadow(QtGui.QFrame.Sunken)
        self.line_8.setObjectName("line_8")
        self.hboxlayout.addWidget(self.line_8)

        self.gridlayout = QtGui.QGridLayout()
        self.gridlayout.setObjectName("gridlayout")

        self.label = QtGui.QLabel(self.horizontalLayoutWidget)
        self.label.setMinimumSize(QtCore.QSize(0, 0))
        self.label.setMaximumSize(QtCore.QSize(70, 70))
        self.label.setObjectName("label")
        self.gridlayout.addWidget(self.label, 0, 0, 1, 1)

        self.comboBox = QtGui.QComboBox(self.horizontalLayoutWidget)
        self.comboBox.setMinimumSize(QtCore.QSize(150, 0))
        self.comboBox.setMaximumSize(QtCore.QSize(150, 16777215))
        self.comboBox.setObjectName("comboBox")
        self.gridlayout.addWidget(self.comboBox, 0, 1, 1, 1)

        self.label_2 = QtGui.QLabel(self.horizontalLayoutWidget)
        self.label_2.setObjectName("label_2")
        self.gridlayout.addWidget(self.label_2, 1, 0, 1, 1)

        self.comboBox_2 = QtGui.QComboBox(self.horizontalLayoutWidget)
        self.comboBox_2.setMinimumSize(QtCore.QSize(150, 0))
        self.comboBox_2.setObjectName("comboBox_2")
        self.gridlayout.addWidget(self.comboBox_2, 1, 1, 1, 1)
        self.hboxlayout.addLayout(self.gridlayout)

        self.gridlayout1 = QtGui.QGridLayout()
        self.gridlayout1.setObjectName("gridlayout1")

        self.label_5 = QtGui.QLabel(self.horizontalLayoutWidget)
        self.label_5.setObjectName("label_5")
        self.gridlayout1.addWidget(self.label_5, 1, 0, 1, 1)

        self.TB_history_prev = QtGui.QToolButton(self.horizontalLayoutWidget)
        self.TB_history_prev.setObjectName("TB_history_prev")
        self.TB_history_prev.setIconSize(QSize(20, 20))
        self.TB_history_prev.setIcon(
            QtGui.QIcon("Resources/icons/bw-history-previous.png"))
        self.gridlayout1.addWidget(self.TB_history_prev, 0, 1, 1, 1)

        self.TB_contribs_prev = QtGui.QToolButton(self.horizontalLayoutWidget)
        self.TB_contribs_prev.setObjectName("TB_contribs_prev")
        self.TB_contribs_prev.setIconSize(QSize(20, 20))
        self.TB_contribs_prev.setIcon(
            QtGui.QIcon("Resources/icons/bw-contribs-prev.png"))
        self.gridlayout1.addWidget(self.TB_contribs_prev, 1, 1, 1, 1)

        self.TB_history_next = QtGui.QToolButton(self.horizontalLayoutWidget)
        self.TB_history_next.setObjectName("TB_history_next")
        self.TB_history_next.setIconSize(QSize(20, 20))
        self.TB_history_next.setIcon(
            QtGui.QIcon("Resources/icons/bw-history-next.png"))
        self.gridlayout1.addWidget(self.TB_history_next, 0, 3, 1, 1)

        self.TB_contribs_next = QtGui.QToolButton(self.horizontalLayoutWidget)
        self.TB_contribs_next.setObjectName("TB_contribs_next")
        self.TB_contribs_next.setIconSize(QSize(20, 20))
        self.TB_contribs_next.setIcon(
            QtGui.QIcon("Resources/icons/bw-contribs-next.png"))
        self.gridlayout1.addWidget(self.TB_contribs_next, 1, 3, 1, 1)

        self.label_4 = QtGui.QLabel(self.horizontalLayoutWidget)
        self.label_4.setMaximumSize(QtCore.QSize(70, 16777215))
        self.label_4.setObjectName("label_4")
        self.gridlayout1.addWidget(self.label_4, 0, 0, 1, 1)

        self.listContribs = blobber.Blobber(self.horizontalLayoutWidget)
        self.listContribs.setMinimumSize(QtCore.QSize(300, 20))
        self.listContribs.setMaximumSize(QtCore.QSize(300, 20))
        self.listContribs.setObjectName("listContribs")
        self.gridlayout1.addWidget(self.listContribs, 0, 2, 1, 1)

        self.widget_2 = QtGui.QWidget(self.horizontalLayoutWidget)
        self.widget_2.setMinimumSize(QtCore.QSize(200, 0))
        self.widget_2.setMaximumSize(QtCore.QSize(16777215, 16777215))
        self.widget_2.setObjectName("widget_2")
        self.gridlayout1.addWidget(self.widget_2, 1, 2, 1, 1)
        self.hboxlayout.addLayout(self.gridlayout1)

        self.verticalLayout = QtGui.QWidget(self.centralwidget)
        self.verticalLayout.setGeometry(QtCore.QRect(0, 110, 201, 401))
        self.verticalLayout.setObjectName("verticalLayout")

        self.vboxlayout = QtGui.QVBoxLayout(self.verticalLayout)
        self.vboxlayout.setSpacing(3)
        self.vboxlayout.setContentsMargins(5, 3, 3, 3)
        self.vboxlayout.setObjectName("vboxlayout")

        self.numitems = QtGui.QLabel(self.verticalLayout)
        self.numitems.setMaximumSize(QtCore.QSize(16777215, 15))
        self.numitems.setObjectName("numitems")
        self.vboxlayout.addWidget(self.numitems)

        self.listitems = QtGui.QWidget(self.verticalLayout)
        self.listitems.setObjectName("listitems")
        self.vboxlayout.addWidget(self.listitems)

        self.msgBox = QtGui.QListWidget(self.centralwidget)
        self.msgBox.setGeometry(QtCore.QRect(0, 523, 1061, 81))
        self.msgBox.setObjectName("msgBox")

        self.horizontalLayout = QtGui.QWidget(self.centralwidget)
        self.horizontalLayout.setGeometry(QtCore.QRect(1, 60, 857, 65))
        self.horizontalLayout.setObjectName("horizontalLayout")

        self.hboxlayout1 = QtGui.QHBoxLayout(self.horizontalLayout)
        self.hboxlayout1.setContentsMargins(5, 3, 3, 3)
        self.hboxlayout1.setObjectName("hboxlayout1")

        self.TB_browser_prev = QtGui.QToolButton(self.horizontalLayout)
        self.TB_browser_prev.setMinimumSize(QtCore.QSize(35, 35))
        self.TB_browser_prev.setIconSize(QSize(35, 35))
        self.TB_browser_prev.setIcon(
            QtGui.QIcon("Resources/icons/bw-browser-prev.png"))
        self.TB_browser_prev.setObjectName("TB_browser_prev")
        self.hboxlayout1.addWidget(self.TB_browser_prev)

        self.TB_browser_next = QtGui.QToolButton(self.horizontalLayout)
        self.TB_browser_next.setMinimumSize(QtCore.QSize(35, 35))
        self.TB_browser_next.setIconSize(QSize(35, 35))
        self.TB_browser_next.setIcon(
            QtGui.QIcon("Resources/icons/bw-browser-next.png"))
        self.TB_browser_next.setObjectName("TB_browser_next")
        self.hboxlayout1.addWidget(self.TB_browser_next)

        self.line_3 = QtGui.QFrame(self.horizontalLayout)
        self.line_3.setFrameShape(QtGui.QFrame.VLine)
        self.line_3.setFrameShadow(QtGui.QFrame.Sunken)
        self.line_3.setObjectName("line_3")
        self.hboxlayout1.addWidget(self.line_3)

        self.TB_browser_open = QtGui.QToolButton(self.horizontalLayout)
        self.TB_browser_open.setMinimumSize(QtCore.QSize(35, 35))
        self.TB_browser_open.setIconSize(QSize(35, 35))
        self.TB_browser_open.setIcon(
            QtGui.QIcon("Resources/icons/bw-browser-open.png"))
        self.TB_browser_open.setObjectName("TB_browser_open")
        self.hboxlayout1.addWidget(self.TB_browser_open)

        self.TB_browser_add_tab = QtGui.QToolButton(self.horizontalLayout)
        self.TB_browser_add_tab.setMinimumSize(QtCore.QSize(35, 35))
        self.TB_browser_add_tab.setIconSize(QSize(35, 35))
        self.TB_browser_add_tab.setIcon(
            QtGui.QIcon("Resources/icons/bw-browser-add-tab.png"))
        self.TB_browser_add_tab.setObjectName("TB_browser_add_tab")
        self.hboxlayout1.addWidget(self.TB_browser_add_tab)

        self.TB_browser_remove_tab = QtGui.QToolButton(self.horizontalLayout)
        self.TB_browser_remove_tab.setMinimumSize(QtCore.QSize(35, 35))
        self.TB_browser_remove_tab.setIconSize(QSize(35, 35))
        self.TB_browser_remove_tab.setIcon(
            QtGui.QIcon("Resources/icons/bw-browser-remove-tab.png"))
        self.TB_browser_remove_tab.setObjectName("TB_browser_remove_tab")
        self.hboxlayout1.addWidget(self.TB_browser_remove_tab)

        self.line_4 = QtGui.QFrame(self.horizontalLayout)
        self.line_4.setFrameShape(QtGui.QFrame.VLine)
        self.line_4.setFrameShadow(QtGui.QFrame.Sunken)
        self.line_4.setObjectName("line_4")
        self.hboxlayout1.addWidget(self.line_4)

        self.TB_history_prev_2 = QtGui.QToolButton(self.horizontalLayout)
        self.TB_history_prev_2.setMinimumSize(QtCore.QSize(35, 35))
        self.TB_history_prev_2.setIconSize(QSize(35, 35))
        self.TB_history_prev_2.setIcon(
            QtGui.QIcon("Resources/icons/bw-history-previous.png"))
        self.TB_history_prev_2.setObjectName("TB_history_prev_2")
        self.hboxlayout1.addWidget(self.TB_history_prev_2)

        self.TB_history_next_2 = QtGui.QToolButton(self.horizontalLayout)
        self.TB_history_next_2.setMinimumSize(QtCore.QSize(35, 35))
        self.TB_history_next_2.setIconSize(QSize(35, 35))
        self.TB_history_next_2.setIcon(
            QtGui.QIcon("Resources/icons/bw-history-next.png"))
        self.TB_history_next_2.setObjectName("TB_history_next_2")
        self.hboxlayout1.addWidget(self.TB_history_next_2)

        self.TB_history_last = QtGui.QToolButton(self.horizontalLayout)
        self.TB_history_last.setMinimumSize(QtCore.QSize(35, 35))
        self.TB_history_last.setIconSize(QSize(35, 35))
        self.TB_history_last.setIcon(
            QtGui.QIcon("Resources/icons/bw-history-last.png"))
        self.TB_history_last.setObjectName("TB_history_last")
        self.hboxlayout1.addWidget(self.TB_history_last)

        self.TB_history_to_cur = QtGui.QToolButton(self.horizontalLayout)
        self.TB_history_to_cur.setMinimumSize(QtCore.QSize(35, 35))
        self.TB_history_to_cur.setIconSize(QSize(35, 35))
        self.TB_history_to_cur.setIcon(
            QtGui.QIcon("Resources/icons/bw-history-to-cur.png"))
        self.TB_history_to_cur.setObjectName("TB_history_to_cur")
        self.hboxlayout1.addWidget(self.TB_history_to_cur)

        self.line_5 = QtGui.QFrame(self.horizontalLayout)
        self.line_5.setFrameShape(QtGui.QFrame.VLine)
        self.line_5.setFrameShadow(QtGui.QFrame.Sunken)
        self.line_5.setObjectName("line_5")
        self.hboxlayout1.addWidget(self.line_5)

        self.TB_contribs_prev_2 = QtGui.QToolButton(self.horizontalLayout)
        self.TB_contribs_prev_2.setMinimumSize(QtCore.QSize(35, 35))
        self.TB_contribs_prev_2.setIconSize(QSize(35, 35))
        self.TB_contribs_prev_2.setIcon(
            QtGui.QIcon("Resources/icons/bw-contribs-prev.png"))
        self.TB_contribs_prev_2.setObjectName("TB_contribs_prev_2")
        self.hboxlayout1.addWidget(self.TB_contribs_prev_2)

        self.TB_contribs_next_2 = QtGui.QToolButton(self.horizontalLayout)
        self.TB_contribs_next_2.setMinimumSize(QtCore.QSize(35, 35))
        self.TB_contribs_next_2.setIconSize(QSize(35, 35))
        self.TB_contribs_next_2.setIcon(
            QtGui.QIcon("Resources/icons/bw-contribs-next.png"))
        self.TB_contribs_next_2.setObjectName("TB_contribs_next_2")
        self.hboxlayout1.addWidget(self.TB_contribs_next_2)

        self.TB_contribs_last = QtGui.QToolButton(self.horizontalLayout)
        self.TB_contribs_last.setMinimumSize(QtCore.QSize(35, 35))
        self.TB_contribs_last.setIconSize(QSize(35, 35))
        self.TB_contribs_last.setIcon(
            QtGui.QIcon("Resources/icons/bw-contribs-last.png"))
        self.TB_contribs_last.setObjectName("TB_contribs_last")
        self.hboxlayout1.addWidget(self.TB_contribs_last)

        self.line_6 = QtGui.QFrame(self.horizontalLayout)
        self.line_6.setFrameShape(QtGui.QFrame.VLine)
        self.line_6.setFrameShadow(QtGui.QFrame.Sunken)
        self.line_6.setObjectName("line_6")
        self.hboxlayout1.addWidget(self.line_6)

        self.TB_page_view = QtGui.QToolButton(self.horizontalLayout)
        self.TB_page_view.setMinimumSize(QtCore.QSize(35, 35))
        self.TB_page_view.setIconSize(QSize(35, 35))
        self.TB_page_view.setIcon(
            QtGui.QIcon("Resources/icons/bw-page-view.png"))
        self.TB_page_view.setObjectName("TB_page_view")
        self.hboxlayout1.addWidget(self.TB_page_view)

        self.TB_page_edit = QtGui.QToolButton(self.horizontalLayout)
        self.TB_page_edit.setMinimumSize(QtCore.QSize(35, 35))
        self.TB_page_edit.setIconSize(QSize(35, 35))
        self.TB_page_edit.setIcon(
            QtGui.QIcon("Resources/icons/bw-page-edit.png"))
        self.TB_page_edit.setObjectName("TB_page_edit")
        self.hboxlayout1.addWidget(self.TB_page_edit)

        self.TB_page_tag = QtGui.QToolButton(self.horizontalLayout)
        self.TB_page_tag.setMinimumSize(QtCore.QSize(35, 35))
        self.TB_page_tag.setIconSize(QSize(35, 35))
        self.TB_page_tag.setIcon(
            QtGui.QIcon("Resources/icons/bw-page-tag.png"))
        self.TB_page_tag.setObjectName("TB_page_tag")
        self.hboxlayout1.addWidget(self.TB_page_tag)

        self.TB_page_delete = QtGui.QToolButton(self.horizontalLayout)
        self.TB_page_delete.setMinimumSize(QtCore.QSize(35, 35))
        self.TB_page_delete.setIconSize(QSize(35, 35))
        self.TB_page_delete.setIcon(
            QtGui.QIcon("Resources/icons/bw-page-delete.png"))
        self.TB_page_delete.setObjectName("TB_page_delete")
        self.hboxlayout1.addWidget(self.TB_page_delete)

        self.TB_page_watch = QtGui.QToolButton(self.horizontalLayout)
        self.TB_page_watch.setMinimumSize(QtCore.QSize(35, 35))
        self.TB_page_watch.setIconSize(QSize(35, 35))
        self.TB_page_watch.setIcon(
            QtGui.QIcon("Resources/icons/bw-page-watch.png"))
        self.TB_page_watch.setObjectName("TB_page_watch")
        self.hboxlayout1.addWidget(self.TB_page_watch)

        self.line_7 = QtGui.QFrame(self.horizontalLayout)
        self.line_7.setFrameShape(QtGui.QFrame.VLine)
        self.line_7.setFrameShadow(QtGui.QFrame.Sunken)
        self.line_7.setObjectName("line_7")
        self.hboxlayout1.addWidget(self.line_7)

        self.TB_user_info = QtGui.QToolButton(self.horizontalLayout)
        self.TB_user_info.setMinimumSize(QtCore.QSize(35, 35))
        self.TB_user_info.setIconSize(QSize(35, 35))
        self.TB_user_info.setIcon(
            QtGui.QIcon("Resources/icons/bw-user-info.png"))
        self.TB_user_info.setObjectName("TB_user_info")
        self.hboxlayout1.addWidget(self.TB_user_info)

        self.TB_user_talk = QtGui.QToolButton(self.horizontalLayout)
        self.TB_user_talk.setMinimumSize(QtCore.QSize(35, 35))
        self.TB_user_talk.setIconSize(QSize(35, 35))
        self.TB_user_talk.setIcon(
            QtGui.QIcon("Resources/icons/bw-user-talk.png"))
        self.TB_user_talk.setObjectName("TB_user_talk")
        self.hboxlayout1.addWidget(self.TB_user_talk)

        self.TB_user_message = QtGui.QToolButton(self.horizontalLayout)
        self.TB_user_message.setMinimumSize(QtCore.QSize(35, 35))
        self.TB_user_message.setIconSize(QSize(35, 35))
        self.TB_user_message.setIcon(
            QtGui.QIcon("Resources/icons/bw-user-message.png"))
        self.TB_user_message.setObjectName("TB_user_message")
        self.hboxlayout1.addWidget(self.TB_user_message)

        self.TB_user_report = QtGui.QToolButton(self.horizontalLayout)
        self.TB_user_report.setMinimumSize(QtCore.QSize(35, 35))
        self.TB_user_report.setIconSize(QSize(35, 35))
        self.TB_user_report.setIcon(
            QtGui.QIcon("Resources/icons/bw-user-report.png"))
        self.TB_user_report.setObjectName("TB_user_report")
        self.hboxlayout1.addWidget(self.TB_user_report)

        self.visor = KHTMLPart(self.centralwidget)
        self.visor.setObjectName("visor")
        self.visor.begin()
        self.visor.view().setGeometry(QtCore.QRect(210, 120, 881, 401))
        #        self.visor.view()
        self.visor.view().setSizePolicy(QtGui.QSizePolicy.Expanding,
                                        QtGui.QSizePolicy.Expanding)

        url = "http://" + config.language + "." + config.project + ".org"

        self.visor.openUrl(KUrl(url))
        #        self.vboxlayout1.addWidget(self.visor.view())

        self.visor.show()
        self.extension = self.visor.browserExtension()
        self.setCentralWidget(self.centralwidget)

        self.menubar = QtGui.QMenuBar(self)
        self.menubar.setGeometry(QtCore.QRect(0, 0, 1270, 27))
        self.menubar.setObjectName("menubar")

        self.menuSystem = QtGui.QMenu(self.menubar)
        self.menuSystem.setObjectName("menuSystem")

        self.menuQueue = QtGui.QMenu(self.menubar)
        self.menuQueue.setObjectName("menuQueue")

        self.menu_page = QtGui.QMenu(self.menubar)
        self.menu_page.setObjectName("menu_page")

        self.menuUser = QtGui.QMenu(self.menubar)
        self.menuUser.setObjectName("menuUser")

        self.menuBrowser = QtGui.QMenu(self.menubar)
        self.menuBrowser.setObjectName("menuBrowser")

        self.menuHelp = QtGui.QMenu(self.menubar)
        self.menuHelp.setObjectName("menuHelp")
        self.setMenuBar(self.menubar)

        self.statusbar = QtGui.QStatusBar(self)
        self.statusbar.setObjectName("statusbar")
        self.setStatusBar(self.statusbar)

        self.menubar.addAction(self.menuSystem.menuAction())
        self.menubar.addAction(self.menuQueue.menuAction())
        self.menubar.addAction(self.menu_page.menuAction())
        self.menubar.addAction(self.menuUser.menuAction())
        self.menubar.addAction(self.menuBrowser.menuAction())
        self.menubar.addAction(self.menuHelp.menuAction())
        self.label.setBuddy(self.comboBox)
        self.label_2.setBuddy(self.comboBox_2)

        self.retranslateUi()
        QtCore.QMetaObject.connectSlotsByName(self)
        self.setTabOrder(self.comboBox, self.comboBox_2)
        self.setTabOrder(self.comboBox_2, self.TB_history_prev)
        self.setTabOrder(self.TB_history_prev, self.TB_contribs_prev)
        self.setTabOrder(self.TB_contribs_prev, self.TB_history_next)
        self.setTabOrder(self.TB_history_next, self.TB_contribs_next)
        self.setTabOrder(self.TB_contribs_next, self.msgBox)
Ejemplo n.º 31
0
    CheckArguments(1)

    app = KApplication()
    command = args.arg(0).toLocal8Bit()
    if command == "properties":
        CheckArguments(2)
        fileList = []
        for index in range(1, args.count()):
            fileList.append(KFileItem(args.url(index), "", 0))

        propertiesDialog = KPropertiesDialog(KFileItemList(fileList))
        propertiesDialog.exec_()
    elif command == "openwith":
        CheckArguments(2)
        fileList = []
        for index in range(1, args.count()):
            fileList.append(args.url(index))

        fileList = KUrl.List(fileList)
        propertiesDialog = KOpenWithDialog(fileList)
        if propertiesDialog.exec_():
            service = propertiesDialog.service()
            if service == None:
                print("No service set, running " + propertiesDialog.text() +
                      "\n")
                service = KService(propertiesDialog.text(),
                                   propertiesDialog.text(), "")
            KRun.run(service, fileList, None)
    else:
        Help()
Ejemplo n.º 32
0
 def openWebPage(self):
     kurl = KUrl(self.url.text())
     krun(kurl, QWidget(), False)
Ejemplo n.º 33
0
class FuzzyOpen(QDialog):
    reason = ""

    def __init__(self, parent=None, connections={}):
        self.urls = []
        self.projectPaths = []

        QDialog.__init__(self, parent)
        uic.loadUi(os.path.join(os.path.dirname(__file__), "fuzzyopen.ui"), self)
        self.setModal(True)
        self.listUrl.setItemDelegate(HtmlItemDelegate(self.listUrl))
        self.hideProgress()

        self.iconLoader = KIconLoader()
        self.btnSettings.setIcon(QIcon(self.iconLoader.loadIcon("configure", KIconLoader.Small)))
        self.btnRefresh.setIcon(QIcon(self.iconLoader.loadIcon("view-refresh", KIconLoader.Small)))

        self.config = KConfig("katefuzzyopenrc")
        configPaths = self.config.group("ProjectPaths")
        for key in configPaths.keyList():
            path = configPaths.readPathEntry(key, "")
            if not path.endswith("/"):
                path += "/"
            self.projectPaths.append(path)

        configFilters = self.config.group("Filters")
        self.lister = DirLister()
        self.lister.fileFound.connect(self.listerFileFound)
        self.lister.directoryChanged.connect(self.listerDirChanged)
        self.lister.completed.connect(self.listerCompleted)
        self.lister.setIncludeFilters(configFilters.readEntry("include", ""))
        self.lister.setExcludeFilters(configFilters.readEntry("exclude", "~$\n\.bak$\n/\."))

    def showEvent(self, event):
        katerect = kate.mainInterfaceWindow().window().rect()
        diarect = self.rect()
        diarect.moveCenter(katerect.center())
        self.move(diarect.topLeft())

        self.reset()
        self.list()

    def getProjectUrl(self, url):
        for path in self.projectPaths:
            if url.url().startswith(path):
                return path
        return False

    def showProgress(self, text):
        self.lblProgress.setText(text)
        self.lblProgress.show()

    def hideProgress(self):
        self.lblProgress.hide()

    def reset(self):
        self.urls = []
        self.txtFilter.setText("")
        self.txtFilter.setFocus()
        self.listUrl.clear()
        self.lister.stop()

    def list(self):
        url = kate.activeDocument().url()
        self.project = self.getProjectUrl(url)

        for doc in kate.documentManager.documents():
            self.addFileUrl(doc.url(), "Open document")

        if self.project:
            self.reason = "In project %s" % self.project
            self.rootPath = KUrl(self.project)
        else:
            self.reason = "Same path of %s" % url.fileName()
            self.rootPath = url.upUrl()

        self.lister.list(self.rootPath, recurse=self.project != False)

    def addFileUrl(self, url, reason=None):
        if url not in self.urls:
            mime = KMimeType.findByUrl(url)[0]
            path = url.url()
            filename = url.fileName()

            item = QListWidgetItem()
            if self.project and path.startswith(self.project):
                path = path[len(self.project):]
                item.setWhatsThis(path)
                item.setText("<b>%s</b>: <i>%s</i>" % (filename, path))
            else:
                item.setWhatsThis(filename)
                item.setText("<b>%s</b>" % filename)
            if reason:
                item.setToolTip(reason)
            item.setIcon(QIcon(self.iconLoader.loadMimeTypeIcon(mime.iconName(), KIconLoader.Small)))
            self.listUrl.addItem(item)

            if url.fileName().find(self.txtFilter.text()) < 0:
                self.listUrl.setItemHidden(item, True)
            self.urls.append(url)

            self.refreshFilter()

    def refreshFilter(self):
        self.on_txtFilter_textEdited(self.txtFilter.text())

    def on_txtFilter_textEdited(self, s):
        firstMatch = -1
        pattern = re.compile(".*".join([re.escape(c) for c in s]), re.I)
        for i in range(self.listUrl.count()):
            matched = pattern.search(self.listUrl.item(i).whatsThis())
            if matched and firstMatch < 0:
                firstMatch = i
            self.listUrl.setItemHidden(self.listUrl.item(i), matched is None)
        self.listUrl.setItemSelected(self.listUrl.item(firstMatch), True)

    def on_txtFilter_keyPressed(self, event):
        selected = self.listUrl.selectedItems()
        if selected:
            current_index = self.listUrl.row(selected[0])
        else:
            current_index = -1

        increment = 0
        if event.key() == Qt.Key_Up:
            increment = -1
        elif event.key() == Qt.Key_Down:
            increment = 1

        if increment != 0:
            current_index += increment
            while 0 <= current_index < self.listUrl.count():
                if self.listUrl.isRowHidden(current_index):
                    current_index += increment
                else:
                    self.listUrl.setItemSelected(self.listUrl.item(current_index), True)
                    current_index = -1

    def on_txtFilter_returnPressed(self):
        if len(self.listUrl.selectedItems()) > 0:
            self.on_listUrl_itemActivated(self.listUrl.selectedItems()[0])

    def on_listUrl_itemActivated(self, item):
        self.lister.stop()
        self.close()
        i = self.listUrl.row(item)
        if 0 <= i < len(self.urls):
            url = self.urls[i]
            kate.mainInterfaceWindow().activateView(kate.documentManager.openUrl(url))

    @pyqtSignature("")
    def on_btnSettings_clicked(self):
        settingsDialog = SettingsDialog(kate.activeDocument().url(), self)
        settingsDialog.txtIncludePatterns.setPlainText("\n".join([r.pattern for r in self.lister.includeFilters]))
        settingsDialog.txtExcludePatterns.setPlainText("\n".join([r.pattern for r in self.lister.excludeFilters]))
        for path in self.projectPaths:
            settingsDialog.listProjectPaths.addItem(path)

        if settingsDialog.exec_():
            configPaths = self.config.group("ProjectPaths")
            for key in configPaths.keyList():
                configPaths.deleteEntry(key)
            self.projectPaths = []
            i = 0
            while i < settingsDialog.listProjectPaths.count():
                item = settingsDialog.listProjectPaths.item(i)
                configPaths.writePathEntry("path%s" % i, item.text())
                self.projectPaths.append(item.text())
                i += 1

            configFilters = self.config.group("Filters")
            includeFilters = settingsDialog.txtIncludePatterns.toPlainText()
            self.lister.setIncludeFilters(includeFilters)
            configFilters.writeEntry("include", includeFilters)

            excludeFilters = settingsDialog.txtExcludePatterns.toPlainText()
            self.lister.setExcludeFilters(excludeFilters)
            configFilters.writeEntry("exclude", excludeFilters)

            self.config.sync()

    @pyqtSignature("")
    def on_btnRefresh_clicked(self):
        url = self.rootPath.url()
        for k in self.lister.cache.keys():
            if k.startswith(url):
                del self.lister.cache[k]
        self.reset()
        self.list()

    def listerFileFound(self, url):
        QApplication.processEvents()
        self.addFileUrl(url, self.reason)

    def listerDirChanged(self, url):
        self.showProgress(url.url())

    def listerCompleted(self):
        self.hideProgress()
Ejemplo n.º 34
0
    def generate(self):
	call(['qrencode', '-s', str(10), '-m', str(3), '-o', '/tmp/qrencoder.png', self.text.text()])
	self.webView.setUrl(KUrl("file:///tmp/qrencoder.png"))