def on_removeButton_clicked(self):
     """
     Private slot to remove a custom toolbar
     """
     name = self.toolbarComboBox.currentText()
     res = KQMessageBox.question(self,
         self.trUtf8("Remove Toolbar"),
         self.trUtf8("""Should the toolbar <b>%1</b> really be removed?""")\
             .arg(name),
         QMessageBox.StandardButtons(\
             QMessageBox.No | \
             QMessageBox.Yes),
         QMessageBox.No)
     if res == QMessageBox.Yes:
         index = self.toolbarComboBox.currentIndex()
         tbItemID = self.toolbarComboBox.itemData(index).toULongLong()[0]
         tbItem = self.__toolbarItems[tbItemID]
         if tbItem.toolBarId is not None and \
            tbItem.toolBarId not in self.__removedToolBarIDs:
             self.__removedToolBarIDs.append(tbItem.toolBarId)
         del self.__toolbarItems[tbItemID]
         for widgetActionID in self.__toolBarItemToWidgetActionID[tbItemID]:
             self.__widgetActionToToolBarItemID[widgetActionID] = None
         del self.__toolBarItemToWidgetActionID[tbItemID]
         self.toolbarComboBox.removeItem(index)
 def createRequest(self, op, request, outgoingData = None):
     """
     Protected method to create a request.
     
     @param op the operation to be performed (QNetworkAccessManager.Operation)
     @param request reference to the request object (QNetworkRequest)
     @param outgoingData reference to an IODevice containing data to be sent
         (QIODevice)
     @return reference to the created reply object (QNetworkReply)
     """
     if op != QNetworkAccessManager.GetOperation:
         return None
     
     if request.url().path() != "subscribe":
         return None
     
     subscription = AdBlockSubscription(request.url(), 
                         Helpviewer.HelpWindow.HelpWindow.adblockManager())
     
     res = KQMessageBox.question(None,
         self.trUtf8("Subscribe?"),
         self.trUtf8("""<p>Subscribe to this AdBlock subscription?</p><p>%1</p>""")\
             .arg(subscription.title()),
         QMessageBox.StandardButtons(\
             QMessageBox.No | \
             QMessageBox.Yes))
     if res == QMessageBox.Yes:
         Helpviewer.HelpWindow.HelpWindow.adblockManager()\
             .addSubscription(subscription)
         dlg = Helpviewer.HelpWindow.HelpWindow.adblockManager().showDialog()
         model = dlg.model()
         dlg.setCurrentIndex(model.index(model.rowCount() - 1, 0))
         dlg.setFocus()
     
     return EmptyNetworkReply(self.parent())
예제 #3
0
    def __confirmAddition(self, engine):
        """
        Private method to confirm the addition of a new search engine.
        
        @param engine reference to the engine to be added (OpenSearchEngine)
        @return flag indicating the engine shall be added (boolean)
        """
        if engine is None or not engine.isValid():
            return False

        host = QUrl(engine.searchUrlTemplate()).host()

        res = KQMessageBox.question(
            None,
            QString(""),
            self.trUtf8(
                """<p>Do you want to add the following engine to your list of"""
                """ search engines?<br/><br/>Name: %1<br/>Searches on: %2</p>"""
            )
            .arg(engine.name())
            .arg(host),
            QMessageBox.StandardButtons(QMessageBox.No | QMessageBox.Yes),
            QMessageBox.No,
        )
        return res == QMessageBox.Yes
 def __getFileName(self):
     """
     Private method to get the filename to save to from the user.
     
     @return flag indicating success (boolean)
     """
     downloadDirectory = Preferences.getUI("DownloadPath")
     if downloadDirectory.isEmpty():
         downloadDirectory = \
             QDesktopServices.storageLocation(QDesktopServices.DocumentsLocation)
     if not downloadDirectory.isEmpty():
         downloadDirectory += '/'
     
     defaultFileName = self.__saveFileName(downloadDirectory)
     fileName = defaultFileName
     baseName = QFileInfo(fileName).completeBaseName()
     self.__autoOpen = False
     if not self.__toDownload:
         res = KQMessageBox.question(None,
             self.trUtf8("Downloading"),
             self.trUtf8("""<p>You are about to download the file <b>%1</b>.</p>"""
                         """<p>What do you want to do?</p>""").arg(fileName),
             QMessageBox.StandardButtons(\
                 QMessageBox.Open | \
                 QMessageBox.Save | \
                 QMessageBox.Cancel))
         if res == QMessageBox.Cancel:
             self.__stop()
             self.close()
             return False
         
         self.__autoOpen = res == QMessageBox.Open
         fileName = QDesktopServices.storageLocation(QDesktopServices.TempLocation) + \
                     '/' + QFileInfo(fileName).completeBaseName()
     
     if not self.__autoOpen and self.__requestFilename:
         fileName = KQFileDialog.getSaveFileName(\
             None,
             self.trUtf8("Save File"),
             defaultFileName,
             QString(),
             None)
         if fileName.isEmpty():
             self.__reply.close()
             if not self.keepOpenCheckBox.isChecked():
                 self.close()
                 return False
             else:
                 self.filenameLabel.setText(self.trUtf8("Download canceled: %1")\
                     .arg(QFileInfo(defaultFileName).fileName()))
                 self.__stop()
                 return True
     
     self.__output.setFileName(fileName)
     self.filenameLabel.setText(QFileInfo(self.__output.fileName()).fileName())
     if self.__requestFilename:
         self.__readyRead()
     
     return True
 def __clearHistoryDialog(self):
     """
     Private slot to clear the history.
     """
     if self.__historyManager is not None and \
        KQMessageBox.question(None,
             self.trUtf8("Clear History"),
             self.trUtf8("""Do you want to clear the history?"""),
             QMessageBox.StandardButtons(\
                 QMessageBox.No | \
                 QMessageBox.Yes),
             QMessageBox.No) == QMessageBox.Yes:
         self.__historyManager.clear()
예제 #6
0
 def on_buttonBox_rejected(self):
     """
     Private slot to handle the rejected signal of the button box.
     """
     res = KQMessageBox.question(
         self,
         self.trUtf8("Close dialog"),
         self.trUtf8("""Do you really want to close the dialog?"""),
         QMessageBox.StandardButtons(QMessageBox.No | QMessageBox.Yes),
         QMessageBox.No,
     )
     if res == QMessageBox.Yes:
         self.reject()
 def keyPressEvent(self, ev):
     """
     Re-implemented to handle the user pressing the escape key.
     
     @param ev key event (QKeyEvent)
     """
     if ev.key() == Qt.Key_Escape:
         res = KQMessageBox.question(self,
             self.trUtf8("Close dialog"),
             self.trUtf8("""Do you really want to close the dialog?"""),
             QMessageBox.StandardButtons(\
                 QMessageBox.No | \
                 QMessageBox.Yes),
             QMessageBox.No)
         if res == QMessageBox.Yes:
             self.reject()
 def on_passwordsButton_clicked(self):
     """
     Private slot to switch the password display mode.
     """
     if self.__passwordModel.showPasswords():
         self.__passwordModel.setShowPasswords(False)
         self.passwordsButton.setText(self.__showPasswordsText)
     else:
         res = KQMessageBox.question(self,
             self.trUtf8("Saved Passwords"),
             self.trUtf8("""Do you really want to show passwords?"""),
             QMessageBox.StandardButtons(\
                 QMessageBox.No | \
                 QMessageBox.Yes),
             QMessageBox.No)
         if res == QMessageBox.Yes:
             self.__passwordModel.setShowPasswords(True)
             self.passwordsButton.setText(self.__hidePasswordsText)
     self.__calculateHeaderSizes()
 def on_removeButton_clicked(self):
     """
     Private slot to remove a document from the help database.
     """
     res = KQMessageBox.question(None,
         self.trUtf8("Remove Documentation"),
         self.trUtf8("""Do you really want to remove the selected documentation """
                     """sets from the database?"""),
         QMessageBox.StandardButtons(\
             QMessageBox.No | \
             QMessageBox.Yes),
         QMessageBox.No)
     if res == QMessageBox.No:
         return
     
     openedDocs = self.__mw.getSourceFileList()
     
     items = self.documentsList.selectedItems()
     for item in items:
         ns = item.text()
         if ns in openedDocs.values():
             res = KQMessageBox.information(self,
                 self.trUtf8("Remove Documentation"),
                 self.trUtf8("""Some documents currently opened reference the """
                             """documentation you are attempting to remove. """
                             """Removing the documentation will close those """
                             """documents."""),
                 QMessageBox.StandardButtons(\
                     QMessageBox.Cancel | \
                     QMessageBox.Ok))
             if res == QMessageBox.Cancel:
                 return
         self.__unregisteredDocs.append(ns)
         for id in openedDocs:
             if openedDocs[id] == ns and id not in self.__tabsToClose:
                 self.__tabsToClose.append(id)
         itm = self.documentsList.takeItem(self.documentsList.row(item))
         del itm
         
         self.__engine.unregisterDocumentation(ns)
     
     if self.documentsList.count():
         self.documentsList.setCurrentRow(0, QItemSelectionModel.ClearAndSelect)
    def __remove(self):
        """
        Private slot to handle the Remove context menu action.
        """
        itm = self.currentItem()
        res = KQMessageBox.question(self,
            self.trUtf8("Remove Template"),
            self.trUtf8("""<p>Do you really want to remove <b>%1</b>?</p>""")\
                .arg(itm.getName()),
            QMessageBox.StandardButtons(\
                QMessageBox.No | \
                QMessageBox.Yes),
            QMessageBox.No)
        if res != QMessageBox.Yes:
            return

        if isinstance(itm, TemplateGroup):
            self.removeGroup(itm)
        else:
            self.removeEntry(itm)
 def editPaste(self, pasting = False):
     """
     Public slot to paste an image from the clipboard.
     
     @param pasting flag indicating part two of the paste operation (boolean)
     """
     img, ok  = self.__clipboardImage()
     if ok:
         if img.width() > self.__image.width() or img.height() > self.__image.height():
             res = KQMessageBox.question(self,
                 self.trUtf8("Paste"),
                 self.trUtf8("""<p>The clipboard image is larger than the current """
                             """image.<br/>Paste as new image?</p>"""),
                 QMessageBox.StandardButtons(\
                     QMessageBox.No | \
                     QMessageBox.Yes),
                 QMessageBox.No)
             if res == QMessageBox.Yes:
                 self.editPasteAsNew()
             return
         elif not pasting:
             self.__isPasting = True
             self.__clipboardSize = img.size()
         else:
             cmd = IconEditCommand(self, self.trUtf8("Paste Clipboard"), self.__image)
             self.__markImage.fill(self.NoMarkColor.rgba())
             for sx in range(self.__pasteRect.width() + 1):
                 for sy in range(self.__pasteRect.height() + 1):
                     dx = self.__pasteRect.x() + sx
                     dy = self.__pasteRect.y() + sy
                     if True:    # TODO: insert code to test for compositing
                         # Porter-Duff Over composition
                         colorS = img.pixel(sx, sy)
                         colorD = self.__image.pixel(dx, dy)
                         
                         alphaS = qAlpha(colorS) / 255.0
                         alphaD = qAlpha(colorD) / 255.0
                         
                         r = qRed(colorS) * alphaS + \
                             (1 - alphaS) * qRed(colorD) * alphaD
                         g = qGreen(colorS) * alphaS + \
                             (1 - alphaS) * qGreen(colorD) * alphaD
                         b = qBlue(colorS) * alphaS + \
                             (1 - alphaS) * qBlue(colorD) * alphaD
                         a = alphaS + \
                             (1 - alphaS) * alphaD
                         
                         # Remove multiplication by alpha
                         if a > 0:
                             r /= a
                             g /= a
                             b /= a
                         else:
                             r = 0
                             g = 0
                             b = 0
                         
                         ir = int(r + 0.5)
                         if ir < 0:
                             ir = 0
                         elif ir > 255:
                             ir = 255
                         
                         ig = int(g + 0.5)
                         if ig < 0:
                             ig = 0
                         elif ig > 255:
                             ig = 255
                         
                         ib = int(b + 0.5)
                         if ib < 0:
                             ib = 0
                         elif ib > 255:
                             ib = 255
                         
                         ia = int(a * 255 + 0.5)
                         if ia < 0:
                             ia = 0
                         elif ia > 255:
                             ia = 255
                         
                         self.__image.setPixel(dx, dy, qRgba(ir, ig, ib, ia))
                     else:
                         self.__image.setPixel(dx, dy, img.pixel(sx, sy))
             
             self.__undoStack.push(cmd)
             cmd.setAfterImage(self.__image)
             
             self.__updateImageRect(self.__pasteRect.topLeft(), 
                                    self.__pasteRect.bottomRight() + QPoint(1, 1))
     else:
         KQMessageBox.warning(self,
             self.trUtf8("Pasting Image"),
             self.trUtf8("""Invalid image data in clipboard."""))
예제 #12
0
 def _vcsImport(self):
     """
     Protected slot used to import the local project into the repository.
     
     <b>NOTE</b>: 
         This does not necessarily make the local project a vcs controlled
         project. You may have to checkout the project from the repository in 
         order to accomplish that.
     """
     def revertChanges():
         """
         Local function do revert the changes made to the project object.
         """
         self.project.pdata["VCS"] = pdata_vcs[:]
         self.project.pdata["VCSOPTIONS"] = copy.deepcopy(pdata_vcsoptions)
         self.project.pdata["VCSOTHERDATA"] = copy.deepcopy(pdata_vcsother)
         self.project.vcs = vcs
         self.project.vcsProjectHelper = vcsHelper
         self.project.vcsBasicHelper = vcs is None
         self.initMenu(self.project.vcsMenu)
         self.project.setDirty(True)
         self.project.saveProject()
     
     pdata_vcs = self.project.pdata["VCS"][:]
     pdata_vcsoptions = copy.deepcopy(self.project.pdata["VCSOPTIONS"])
     pdata_vcsother = copy.deepcopy(self.project.pdata["VCSOTHERDATA"])
     vcs = self.project.vcs
     vcsHelper = self.project.vcsProjectHelper
     vcsSystemsDict = e4App().getObject("PluginManager")\
         .getPluginDisplayStrings("version_control")
     if not vcsSystemsDict:
         # no version control system found
         return
     
     vcsSystemsDisplay = QStringList()
     keys = vcsSystemsDict.keys()
     keys.sort()
     for key in keys:
         vcsSystemsDisplay.append(vcsSystemsDict[key])
     vcsSelected, ok = KQInputDialog.getItem(\
         None,
         self.trUtf8("Import Project"),
         self.trUtf8("Select version control system for the project"),
         vcsSystemsDisplay,
         0, False)
     if not ok:
         return
     vcsSystem = None
     for vcsSystem, vcsSystemDisplay in vcsSystemsDict.items():
         if vcsSystemDisplay == vcsSelected:
             break
     
     if vcsSystem:
         self.project.pdata["VCS"] = [vcsSystem]
         self.project.vcs = self.project.initVCS(vcsSystem)
         if self.project.vcs is not None:
             vcsdlg = self.project.vcs.vcsOptionsDialog(self.project, self.project.name, 1)
             if vcsdlg.exec_() == QDialog.Accepted:
                 vcsDataDict = vcsdlg.getData()
                 # edit VCS command options
                 vcores = KQMessageBox.question(None,
                     self.trUtf8("Import Project"),
                     self.trUtf8("""Would you like to edit the VCS command options?"""),
                     QMessageBox.StandardButtons(\
                         QMessageBox.No | \
                         QMessageBox.Yes),
                     QMessageBox.No)
                 if vcores == QMessageBox.Yes:
                     codlg = vcsCommandOptionsDialog(self.project.vcs)
                     if codlg.exec_() == QDialog.Accepted:
                         self.project.vcs.vcsSetOptions(codlg.getOptions())
                 self.project.setDirty(True)
                 self.project.vcs.vcsSetDataFromDict(vcsDataDict)
                 self.project.saveProject()
                 isVcsControlled = \
                     self.project.vcs.vcsImport(vcsDataDict, self.project.ppath)[0]
                 if isVcsControlled:
                     # reopen the project
                     self.project.openProject(self.project.pfile)
                 else:
                     # revert the changes to the local project 
                     # because the project dir is not a VCS directory
                     revertChanges()
             else:
                 # revert the changes because user cancelled
                 revertChanges()
예제 #13
0
 def _vcsCheckout(self, export = False):
     """
     Protected slot used to create a local project from the repository.
     
     @param export flag indicating whether an export or a checkout
             should be performed
     """
     if not self.project.checkDirty():
         return
     
     vcsSystemsDict = e4App().getObject("PluginManager")\
         .getPluginDisplayStrings("version_control")
     if not vcsSystemsDict:
         # no version control system found
         return
     
     vcsSystemsDisplay = QStringList()
     keys = vcsSystemsDict.keys()
     keys.sort()
     for key in keys:
         vcsSystemsDisplay.append(vcsSystemsDict[key])
     vcsSelected, ok = KQInputDialog.getItem(\
         None,
         self.trUtf8("New Project"),
         self.trUtf8("Select version control system for the project"),
         vcsSystemsDisplay,
         0, False)
     if not ok:
         return
     for vcsSystem, vcsSystemDisplay in vcsSystemsDict.items():
         if vcsSystemDisplay == vcsSelected:
             break
     
     if not self.project.closeProject():
         return
     
     self.project.pdata["VCS"] = [vcsSystem]
     self.project.vcs = self.project.initVCS(vcsSystem)
     if self.project.vcs is not None:
         vcsdlg = self.project.vcs.vcsNewProjectOptionsDialog()
         if vcsdlg.exec_() == QDialog.Accepted:
             projectdir, vcsDataDict = vcsdlg.getData()
             self.project.pdata["VCS"] = [vcsSystem]
             self.project.vcs = self.project.initVCS(vcsSystem)
             # edit VCS command options
             vcores = KQMessageBox.question(None,
                 self.trUtf8("New Project"),
                 self.trUtf8("""Would you like to edit the VCS command options?"""),
                 QMessageBox.StandardButtons(\
                     QMessageBox.No | \
                     QMessageBox.Yes),
                 QMessageBox.No)
             if vcores == QMessageBox.Yes:
                 codlg = vcsCommandOptionsDialog(self.project.vcs)
                 if codlg.exec_() == QDialog.Accepted:
                     self.project.vcs.vcsSetOptions(codlg.getOptions())
             
             # create the project directory if it doesn't exist already
             if not os.path.isdir(projectdir):
                 try:
                     os.makedirs(projectdir)
                 except EnvironmentError:
                     KQMessageBox.critical(None,
                         self.trUtf8("Create project directory"),
                         self.trUtf8("<p>The project directory <b>%1</b> could not"
                             " be created.</p>").arg(projectdir))
                     self.project.pdata["VCS"] = ['None']
                     self.project.vcs = self.project.initVCS()
                     return
             
             # create the project from the VCS
             self.project.vcs.vcsSetDataFromDict(vcsDataDict)
             if export:
                 ok = self.project.vcs.vcsExport(vcsDataDict, projectdir)
             else:
                 ok = self.project.vcs.vcsCheckout(vcsDataDict, projectdir, False)
             if ok:
                 projectdir = os.path.normpath(projectdir)
                 filters = QStringList() << "*.e4p" << "*.e4pz" << "*.e3p" << "*.e3pz"
                 d = QDir(projectdir)
                 plist = d.entryInfoList(filters)
                 if len(plist):
                     if len(plist) == 1:
                         self.project.openProject(plist[0].absoluteFilePath())
                         self.project.emit(SIGNAL('newProject'))
                     else:
                         pfilenamelist = d.entryList(filters)
                         pfilename, ok = KQInputDialog.getItem(
                             None,
                             self.trUtf8("New project from repository"),
                             self.trUtf8("Select a project file to open."),
                             pfilenamelist, 0, False)
                         if ok:
                             self.project.openProject(\
                                 QFileInfo(d, pfilename).absoluteFilePath())
                             self.project.emit(SIGNAL('newProject'))
                     if export:
                         self.project.pdata["VCS"] = ['None']
                         self.project.vcs = self.project.initVCS()
                         self.project.setDirty(True)
                         self.project.saveProject()
                 else:
                     res = KQMessageBox.question(None,
                         self.trUtf8("New project from repository"),
                         self.trUtf8("The project retrieved from the repository"
                             " does not contain an eric project file"
                             " (*.e4p *.e4pz *.e3p *.e3pz)."
                             " Create it?"),
                         QMessageBox.StandardButtons(\
                             QMessageBox.No | \
                             QMessageBox.Yes),
                         QMessageBox.Yes)
                     if res == QMessageBox.Yes:
                         self.project.ppath = projectdir
                         self.project.opened = True
                         
                         from Project.PropertiesDialog import PropertiesDialog
                         dlg = PropertiesDialog(self.project, False)
                         if dlg.exec_() == QDialog.Accepted:
                             dlg.storeData()
                             self.project.initFileTypes()
                             self.project.setDirty(True)
                             try:
                                 ms = os.path.join(self.project.ppath, 
                                                   self.project.pdata["MAINSCRIPT"][0])
                                 if os.path.exists(ms):
                                     self.project.appendFile(ms)
                             except IndexError:
                                 ms = ""
                             self.project.newProjectAddFiles(ms)
                             self.project.saveProject()
                             self.project.openProject(self.project.pfile)
                             if not export:
                                 res = KQMessageBox.question(None,
                                     self.trUtf8("New project from repository"),
                                     self.trUtf8("Shall the project file be added to"
                                         " the repository?"),
                                     QMessageBox.StandardButtons(\
                                         QMessageBox.No | \
                                         QMessageBox.Yes),
                                     QMessageBox.Yes)
                                 if res == QMessageBox.Yes:
                                     self.project.vcs.vcsAdd(self.project.pfile)
             else:
                 KQMessageBox.critical(None,
                     self.trUtf8("New project from repository"),
                     self.trUtf8("""The project could not be retrieved from"""
                         """ the repository."""))
                 self.project.pdata["VCS"] = ['None']
                 self.project.vcs = self.project.initVCS()
         else:
             self.project.pdata["VCS"] = ['None']
             self.project.vcs = self.project.initVCS()
예제 #14
0
    def __sslErrors(self, reply, errors):
        """
        Private slot to handle SSL errors.
        
        @param reply reference to the reply object (QNetworkReply)
        @param errors list of SSL errors (list of QSslError)
        """
        caMerge = QSslCertificate.fromData(Preferences.Prefs.settings.value("Help/CaCertificates").toByteArray())
        caNew = []

        errorStrings = QStringList()
        for err in errors:
            if err.certificate() in caMerge:
                continue
            errorStrings.append(err.errorString())
            if not err.certificate().isNull():
                caNew.append(err.certificate())
        if errorStrings.isEmpty():
            reply.ignoreSslErrors()
            return

        errorString = errorStrings.join(".</li><li>")
        ret = KQMessageBox.warning(
            None,
            self.trUtf8("SSL Errors"),
            self.trUtf8(
                """<p>SSL Errors for <br /><b>%1</b>"""
                """<ul><li>%2</li></ul></p>"""
                """<p>Do you want to ignore these errors?</p>"""
            )
            .arg(reply.url().toString())
            .arg(errorString),
            QMessageBox.StandardButtons(QMessageBox.No | QMessageBox.Yes),
            QMessageBox.No,
        )

        if ret == QMessageBox.Yes:
            if len(caNew) > 0:
                certinfos = QStringList()
                for cert in caNew:
                    certinfos.append(self.__certToString(cert))
                ret = KQMessageBox.question(
                    None,
                    self.trUtf8("Certificates"),
                    self.trUtf8(
                        """<p>Certificates:<br/>%1<br/>""" """Do you want to accept all these certificates?</p>"""
                    ).arg(certinfos.join("")),
                    QMessageBox.StandardButtons(QMessageBox.No | QMessageBox.Yes),
                    QMessageBox.No,
                )
                if ret == QMessageBox.Yes:
                    for cert in caNew:
                        caMerge.append(cert)

                    sslCfg = QSslConfiguration.defaultConfiguration()
                    caList = sslCfg.caCertificates()
                    for cert in caNew:
                        caList.append(cert)
                    sslCfg.setCaCertificates(caList)
                    sslCfg.setProtocol(QSsl.AnyProtocol)
                    QSslConfiguration.setDefaultConfiguration(sslCfg)
                    reply.setSslConfiguration(sslCfg)

                    pems = QByteArray()
                    for cert in caMerge:
                        pems.append(cert.toPem() + "\n")
                    Preferences.Prefs.settings.setValue("Help/CaCertificates", QVariant(pems))

            reply.ignoreSslErrors()