def on_pluginsList_currentItemChanged(self, cur, prev): if cur: name = cur.data(Qt.UserRole) if name not in self.addons: QMessageBox.critical(self, self._tr("Internal error"), self._tr("Can't find addon {name} in " "list").format(name=name)) return p = self.addons[name] self.nameEdit.setText(p["name"]) self.authorEdit.setText(p["author"]) self.versionEdit.setText(p["version"]) self.descriptionEdit.setPlainText(p["description"]) self.apiEdit.setText(p["apiVersion"]) self.repositoryEdit.setText(p["repository"]) if name in self.host.plugins: if p["version"] > self.host.plugins[name].version: self.installButton.setEnabled(True) self.installButton.setText(self._tr("Update")) else: self.installButton.setEnabled(False) self.installButton.setText(self._tr("Install")) else: self.installButton.setEnabled(True) self.installButton.setText(self._tr("Install")) else: self.nameEdit.clear() self.authorEdit.clear() self.versionEdit.clear() self.descriptionEdit.clear() self.apiEdit.clear() self.repositoryEdit.clear()
def on_installButton_clicked(self): item = self.pluginsList.currentItem() if not item: return name = item.data(Qt.UserRole) if name not in self.addons: QMessageBox.critical(self, self._tr("Internal error"), self._tr("Can't find addon {name} in list"). format(name=name)) return p = self.addons[name] # update?, so remove the local one first if name in self.host.plugins: if p["version"] > self.host.plugins[name].version: devtools.PluginInstaller.removePlugin(name) else: # should not happen (ui restricted) QMessageBox.critical(self, self._tr("Internal error"), self._tr("This plugin is already " "installed")) return self.installer = InstallDialog(self.host, self) self.installer.show() self.installer.install(p)
def Login(self): self.saveSettings() # Grab credentials from the currently available fields, not saved settings. if self.settingsDialog.group_account: Username = self.settingsDialog.group_account.input_username.text Password = self.settingsDialog.group_account.input_password.text # Headers and payload. Headers = {"User-Agent": "ScreenCloud-Cloudup"} Payload = { "client_id": "ah5Oa7F3hT8", "grant_type": "password", "username": Username, "password": Password } try: r = requests.post("https://cloudup.com/oauth/access_token", data = Payload, headers = Headers) j = json.loads(r.text) if r.status_code == 400: QMessageBox.critical(self.settingsDialog, "Cloudup Login Error", j["error_description"]) self.Key = j["access_token"] self.saveSettings() self.loadSettings() self.updateUi() QMessageBox.information(self.settingsDialog, "Success!", "You have successfully signed into your Cloudup account.") except Exception as e: QMessageBox.critical(self.settingsDialog, "Cloudup Login Error", "Error occurred during login. " + e.message)
def startAuthenticationProcess(self): self.settingsDialog.group_account.widget_authorize.button_authenticate.setEnabled( False) self.flow = dropbox.client.DropboxOAuth2FlowNoRedirect( 'sfacmqvdb9dn66r', 'hx8meda636xgsox') authorize_url = QUrl(self.flow.start()) QDesktopServices.openUrl(authorize_url) code = raw_input( "Enter the authorization code from the dropbox website:") if code: try: self.access_token, self.user_id = self.flow.finish(code) self.client = dropbox.client.DropboxClient(self.access_token) self.display_name = self.client.account_info()['display_name'] except dropbox.rest.ErrorResponse: if "win" in sys.platform: #Workaround for crash on windows self.parentWidget.hide() self.settingsDialog.hide() QMessageBox.critical( self.settingsDialog, "Failed to authenticate", "Failed to authenticate with Dropbox. Wrong code?") if "win" in sys.platform: self.settingsDialog.show() self.parentWidget.show() self.saveSettings() self.updateUi()
def startAuthenticationProcess(self): self.settingsDialog.group_account.widget_authorize.button_authenticate.setEnabled( False) authorize_url = QUrl( self.client.auth_provider.get_auth_url(REDIRECT_URI)) QDesktopServices.openUrl(authorize_url) try: code = raw_input( "Copy everything in the address bar after \"code=\", and paste it below:" ) except NameError: code = input( "Copy everything in the address bar after \"code=\", and paste it below:" ) if code: try: self.client.auth_provider.authenticate(code, REDIRECT_URI, None) except: if "win" in sys.platform: #Workaround for crash on windows self.parentWidget.hide() self.settingsDialog.hide() QMessageBox.critical( self.settingsDialog, "Failed to authenticate", "Failed to authenticate with OneDrive. Wrong code?") if "win" in sys.platform: self.settingsDialog.show() self.parentWidget.show() #Set display name self.displayName = self.client.drive.get().owner.user.display_name self.loggedIn = True self.saveSettings() self.updateUi()
def startAuthenticationProcess(self): self.settingsDialog.group_account.widget_authorize.button_authenticate.setEnabled(False) self.flow = dropbox.oauth.DropboxOAuth2FlowNoRedirect('sfacmqvdb9dn66r', 'hx8meda636xgsox') authorize_url = QUrl(self.flow.start()) QDesktopServices.openUrl(authorize_url) try: code = raw_input("Enter the authorization code from the dropbox website:") except NameError: code = input("Enter the authorization code from the dropbox website:") if code: try: oauth2_result = self.flow.finish(code) self.access_token = oauth2_result.access_token self.client = dropbox.Dropbox(self.access_token) account = self.client.users_get_current_account() self.user_id = account.account_id self.display_name = account.name.display_name except dropbox.auth.AccessError: if "win" in sys.platform: #Workaround for crash on windows self.parentWidget.hide() self.settingsDialog.hide() QMessageBox.critical(self.settingsDialog, "Failed to authenticate", "Failed to authenticate with Dropbox. Wrong code?") if "win" in sys.platform: self.settingsDialog.show() self.parentWidget.show() self.saveSettings() self.updateUi()
def on_addButton_clicked(self): (res, name, url) = MultiInputDialog.getTexts(self._tr("Add repository"), self._tr("Name:"), self._tr("URL:"), "", "", self) if res: qurl = QUrl(url) if qurl.isValid() and not qurl.isLocalFile(): rep = dict() rep["name"] = name rep["url"] = url rep["origin"] = "local" rep["active"] = True self.replist[name] = rep item = QListWidgetItem(name) item.setFlags(Qt.ItemIsSelectable | Qt.ItemIsUserCheckable | Qt.ItemIsEnabled) item.setCheckState(Qt.Checked) item.setData(Qt.UserRole, name) self.repositoryList.addItem(item) else: QMessageBox.critical(self._tr("Error"), self._tr("The URL {url} is not valid"). format(url=url))
def pinEntered(self): pin = self.settingsDialog.group_account.input_code.text if pin: try: self.access_token, self.refresh_token = self.imgur.exchange_pin(pin) except KeyError as e: QMessageBox.critical(self.settingsDialog, "Imgur key error", "Failed to exchange pin. " + e.message) return self.access_token, self.username = self.imgur.refresh_access_token() self.saveSettings() self.updateUi()
def on_deleteButton_clicked(self): cur = self.repositoryList.currentItem() if cur: name = cur.data(Qt.UserRole) if name not in self.replist: QMessageBox.critical(self._tr("Internal error"), self._tr("Can't find repository {name} " "in list").format(name=name)) return del self.replist[name] cur.delete()
def authorizationCodeEntered(self): code = self.settingsDialog.group_account.widget_authenticate.input_code.text if code: try: self.access_token, self.user_id = self.flow.finish(code) except dropbox.rest.ErrorResponse: QMessageBox.critical(0, "Failed to authenticate", "Failed to authenticate with Dropbox. Wrong code?") self.settingsDialog.group_account.widget_authenticate.input_code.setText("") return self.client = dropbox.client.DropboxClient(self.access_token) self.display_name = self.client.account_info()["display_name"] self.saveSettings() self.updateUi()
def on_repositoryList_currentItemChanged(self, cur, prev): if cur: name = cur.data(Qt.UserRole) if name not in self.replist: self.deleteButton.setEnabled(False) QMessageBox.critical(self, self._tr("Internal error"), self._tr("Can't find repository {name} " "in list").format(name=name)) return self.deleteButton.setEnabled(True) else: self.deleteButton.setEnabled(False)
def startAuthenticationProcess(self): self.saveSettings() self.loadSettings() auth_url = self.imgur.authorization_url('pin') QDesktopServices.openUrl(QUrl(auth_url)) pin = raw_input("Enter PIN from imgur website:") if pin: try: self.access_token, self.refresh_token = self.imgur.exchange_pin(pin) except KeyError as e: QMessageBox.critical(self.settingsDialog, "Imgur key error", "Failed to exchange pin. " + e.message) self.access_token, self.username = self.imgur.refresh_access_token() self.saveSettings() self.updateUi()
def on_repositoryList_itemChanged(self, item): if not item: return name = item.data(Qt.UserRole) if name not in self.replist: QMessageBox.critical(self, self._tr("Internal error"), self._tr("Can't find repository {name} in " "list").format(name=name)) return if self.replist[name]["active"] != (item.checkState() == Qt.Checked): self.replist[name]["active"] = (item.checkState() == Qt.Checked) self.updateAddonlist()
def showChangelog(cls): fname = pytson.getPluginPath("Changelog.html") if not os.path.isfile(fname): QMessageBox.critical(None, cls._tr("Error"), cls._tr("Can't find " "Changelog")) return with open(fname, "r") as f: # store it just to keep it in scope cls.viewer = viewer = QTextBrowser() viewer.setAttribute(Qt.WA_DeleteOnClose) viewer.openExternalLinks = True viewer.setHtml(f.read()) viewer.show()
def startAuthenticationProcess(self): self.saveSettings() self.loadSettings() auth_url = self.imgur.authorization_url('pin') QDesktopServices.openUrl(QUrl(auth_url)) pin = raw_input("Enter PIN from imgur website:") if pin: try: self.access_token, self.refresh_token = self.imgur.exchange_pin( pin) except KeyError as e: QMessageBox.critical(self.settingsDialog, "Imgur key error", "Failed to exchange pin. " + e.message) self.access_token, self.username = self.imgur.refresh_access_token() self.saveSettings() self.updateUi()
def onPluginsTableItemChanged(self, item): checked = item.checkState() == Qt.Checked name = item.data(Qt.UserRole) if checked and name not in self.host.active: if self.host.activate(name): if self.host.active[name].offersConfigure: self.pluginsTable.cellWidget(item.row(), 1).setEnabled(True) else: item.setCheckState(Qt.Unchecked) QMessageBox.critical(self, self._tr("Activation failed"), self._tr("Error starting plugin, check " "your client log for more information")) elif not checked and name in self.host.active: if self.host.active[name].offersConfigure: self.pluginsTable.cellWidget(item.row(), 1).setEnabled(False) self.host.deactivate(name)
def on_siteremoveButton_clicked(self): ids = {it.data(Qt.UserRole) for it in self.siteTable.selectedItems()} if ids: if (QMessageBox.question(self, self._tr("Remove site packages"), self._tr("Are you sure to remove the " "selected packages? Some " "plugins might not work " "properly.")) == QMessageBox.Yes): try: for idx in ids: devtools.removePackage(self.sitepkgs[idx]["name"], self.sitepkgs[idx]["version"]) except Exception as e: QMessageBox.critical(self, self._tr("Error"), str(e)) self.reloadSite()
def on_repositoryList_doubleClicked(self, item): name = item.data(Qt.UserRole) try: rep = self.replist[name] except: QMessageBox.critical(self, self._tr("Internal error"), self._tr("Can't find repository {name} in " "list").format(name=name)) return ok = BoolResult() newurl = QInputDialog.getText(self, self._tr("Change url of repository " "{name}").format(name=name), self._tr("Url:"), QLineEdit.Normal, rep["url"], ok) if ok: rep["url"] = newurl rep["origin"] = "local"
def startAuthenticationProcess(self): if self.settingsDialog.group_account.input_url.text and self.settingsDialog.group_account.input_username.text and self.settingsDialog.group_account.input_password.text: self.saveSettings() self.loadSettings() if match(self.url, "URI"): try: request = requests.get(self.url, timeout=3); if request.status_code == 200: oc = owncloud.Client(self.url) oc.login(self.username, self.password) self.connectStatus = "true" self.saveSettings() self.updateUi() except requests.exceptions.RequestException as e: QMessageBox.critical(self.settingsDialog, "OwnCloud Connection Error", "The specified Server URL is invalid!") settings = QSettings() settings.remove("connect-status") self.saveSettings() self.updateUi() except Exception as e: errorMessage = self.formatConnectionError(e.message) if errorMessage == "401": self.settingsDialog.group_connection.widget_status.label_status.setText("Invalid") else: QMessageBox.critical(self.settingsDialog, "OwnCloud Connection Error", errorMessage) else: QMessageBox.critical(self.settingsDialog, "OwnCloud Connection Error", "The specified Server URL is invalid!") else: missingFields = "" fieldText = "field" if not self.settingsDialog.group_account.input_url.text: missingFields = "\"Server URL\"" if not self.settingsDialog.group_account.input_username.text: if missingFields == "": missingFields = "\"Username\"" else: missingFields = missingFields + " and \"Username\"" fieldText = "fields" if not self.settingsDialog.group_account.input_password.text: if missingFields == "": missingFields = "\"Password\"" else: missingFields = missingFields.replace(" and", ",") + " and \"Password\"" fieldText = "fields" QMessageBox.critical(self.settingsDialog, "OwnCloud Connection Error", "The " + missingFields + " " + fieldText + " must be filled in!")
def startAuthenticationProcess(self): self.settingsDialog.group_account.widget_authorize.button_authenticate.setEnabled( False) self.flow = client.OAuth2WebServerFlow( client_id=self.clientID, client_secret=self.clientSecret, scope=SCOPES, redirect_uri="urn:ietf:wg:oauth:2.0:oob") authorize_url = QUrl(self.flow.step1_get_authorize_url()) QDesktopServices.openUrl(authorize_url) try: code = raw_input( "Enter the authorization code from the Google Drive website:") except NameError: code = input( "Enter the authorization code from the Google Drive website:") if code: try: oauth2_result = self.flow.step2_exchange(code) self.accessToken = oauth2_result.access_token self.refreshToken = oauth2_result.refresh_token self.driveService = build('drive', 'v3', http=oauth2_result.authorize(Http())) account = self.driveService.about().get( fields="user").execute() self.displayName = account["user"]["displayName"] except client.Error: if "win" in sys.platform: #Workaround for crash on windows self.parentWidget.hide() self.settingsDialog.hide() QMessageBox.critical( self.settingsDialog, "Failed to authenticate", "Failed to authenticate with Google Drive. Wrong code?") if "win" in sys.platform: self.settingsDialog.show() self.parentWidget.show() self.saveSettings() self.updateUi()
def startAuthenticationProcess(self): if self.settingsDialog.group_account.input_url.text and self.settingsDialog.group_account.input_username.text and self.settingsDialog.group_account.input_password.text: self.saveSettings() self.loadSettings() if match(self.url, "URI"): try: request = requests.get(self.url, timeout=3) if request.status_code == 200: oc = nextcloud.Client(self.url) oc.login(self.username, self.password) self.connectStatus = "true" self.saveSettings() self.updateUi() except requests.exceptions.RequestException as e: QMessageBox.critical( self.settingsDialog, "NextCloud Connection Error", "The specified Server URL is invalid!") settings = QSettings() settings.remove("connect-status") self.saveSettings() self.updateUi() except Exception as e: errorMessage = self.formatConnectionError(e.message) if errorMessage == "401": self.settingsDialog.group_connection.widget_status.label_status.setText( "Invalid") else: QMessageBox.critical(self.settingsDialog, "NextCloud Connection Error", errorMessage) else: QMessageBox.critical(self.settingsDialog, "NextCloud Connection Error", "The specified Server URL is invalid!") else: missingFields = "" fieldText = "field" if not self.settingsDialog.group_account.input_url.text: missingFields = "\"Server URL\"" if not self.settingsDialog.group_account.input_username.text: if missingFields == "": missingFields = "\"Username\"" else: missingFields = missingFields + " and \"Username\"" fieldText = "fields" if not self.settingsDialog.group_account.input_password.text: if missingFields == "": missingFields = "\"Password\"" else: missingFields = missingFields.replace( " and", ",") + " and \"Password\"" fieldText = "fields" QMessageBox.critical( self.settingsDialog, "NextCloud Connection Error", "The " + missingFields + " " + fieldText + " must be filled in!")
def errorMsgBox(title, text): QMessageBox.critical(None, title, text)