class MainWindow(QMainWindow, Ui_MainWindow): def __init__(self, parent=None): super(MainWindow, self).__init__(parent) self.current_profileid = "" self.setupUi(self) self.logger = get_logger('desuratools', 'desuratools.log') self.logger.info('Logger Created') boldfont = QApplication.font() boldfont.setBold(True) self.addToSteam_action = self.action_factory("Add to Steam", self.add_to_steam) self.addToSteam_action.setFont(boldfont) self.installGame_action = self.action_factory("Install", self.install_game) self.installGame_action.setFont(boldfont) self.desuraPage_action = self.action_factory("View Profile", self.open_desura_page) self.uninstallGame_action = self.action_factory( "Uninstall", self.uninstall_game) self.verifyGame_action = self.action_factory("Verify", self.verify_game) self.ownedGames_menu = QMenu(self) self.ownedGames_menu.addActions( [self.installGame_action, self.desuraPage_action]) self.installedGames_menu = QMenu(self) self.installedGames_menu.addActions([ self.addToSteam_action, self.desuraPage_action, self.uninstallGame_action, self.verifyGame_action ]) self.selectAllButton.clicked.connect(self.select_all_games) self.desuraAccountName_verify.clicked.connect( self.populate_owned_games) self.installButton.clicked.connect(self.process_install_button) self.generateDesuraReport_action.activated.connect( self.generate_report) self.tabWidget.currentChanged.connect(self.swap_tabs) self.ownedGames_list.itemSelectionChanged.connect(self.update_gameinfo) self.installedGames_list.itemSelectionChanged.connect( self.update_gameinfo) self.refreshButton.clicked.connect(self.refresh_list) self.refreshLists_action.activated.connect(self.refresh_all) self.installedGames_list.customContextMenuRequested.connect( self.show_game_context) self.installedGames_list.doubleClicked.connect(self.add_to_steam) self.installedGames_list.setSelectionMode( QAbstractItemView.ExtendedSelection) self.ownedGames_list.setSelectionMode( QAbstractItemView.ExtendedSelection) self.steamID_input.addItems(steamutils.get_customurls_on_machine()) self.ownedGames_list.addItem( "Verify your Desura username to see your owned games") QApplication.processEvents() self.loading_dialog = ProgressBarDialog() self.loading_dialog.show() QApplication.processEvents() self.populate_installed_games() self.load_data() self.loading_dialog.close() self.raise_() def verify_user(self, profileid=None): if profileid is None: profileid = self.current_profileid if len(profileid) == 0: return False try: username = gameslist.username_from_profile_id(profileid) except gameslist.NoSuchProfileError: return False if windows.desura_running(username): return True verify_dialog = QMessageBox() verify_dialog.setText( "<b>Verify your identity</b><br />Sign in to Desura to continue with account <b>{0}</b> to confirm your identity" .format(username)) verify_dialog.setInformativeText( "<i>Waiting for Desura sign-in...</i>") verify_dialog.setWindowTitle("Sign into Desura to continue") verify_dialog.setStandardButtons(QMessageBox.Cancel) verify_dialog.setIcon(QMessageBox.Information) verify_dialog.setWindowFlags(Qt.CustomizeWindowHint | Qt.WindowTitleHint) desurawaiter = DesuraWaiter(username) desurawaiter.finished.connect(verify_dialog.close) desurawaiter.start() verify_dialog.exec_() if windows.desura_running(username): return True else: desurawaiter.terminate() return False def load_data(self): try: with open(os.path.join(windows.data_dir(), 'desuratools.json'), 'r') as savefile: try: data = json.loads(savefile.read()) except Exception: self.desuraAccountName_input.setText("") return self.desuraAccountName_input.setText(data['desuraname']) if data['desuraname'] != "": self.populate_owned_games() steamid = self.steamID_input.findText(data['steamname']) self.steamID_input.setCurrentIndex(steamid) except IOError: pass def closeEvent(self, *args, **kwargs): self.logger.info("Saving to file") savefile = open(os.path.join(windows.data_dir(), 'desuratools.json'), 'w') savefile.write( json.dumps({ 'desuraname': self.current_profileid, 'steamname': self.steamID_input.currentText() })) savefile.close() QApplication.quit() def populate_qlistwidget(self, game, qlistwidget, iconurls=False): if iconurls: itemicon = self.qpixmap_from_url(game.icon) QApplication.processEvents() else: itemicon = QPixmap(game.icon) QApplication.processEvents() item = QListWidgetItem(itemicon, game.name, qlistwidget) item.setData(Qt.UserRole, game) qlistwidget.addItem(item) def populate_owned_games(self): self.statusBar.showMessage("Waiting for Desura... Please Wait") try: if not self.set_current_account(): if len(self.desuraAccountName_input.text()) > 0: self.statusBar.showMessage("Invalid Desura Account") else: self.statusBar.showMessage("") return self.ownedGames_list.clear() self.loading_dialog.setAccount( gameslist.username_from_profile_id(self.current_profileid)) QApplication.processEvents() self.loading_dialog.setMaximum( len(gameslist.GamesList(self.current_profileid).get_games())) QApplication.processEvents() for game in gameslist.GamesList( self.current_profileid).get_games(): self.populate_qlistwidget(game, self.ownedGames_list, True) QApplication.processEvents() self.loading_dialog.increment(1, game.name) QApplication.processEvents() self.logger.info("Added Game {0}".format(game.name)) self.statusBar.showMessage("Added Game {0}".format(game.name)) except gameslist.PrivateProfileError: self.logger.error("Failed to load games - Private Desura Profile") self.statusBar.showMessage( "Failed to load games - Private Desura Profiles not supported") error_message( "The Desura Profile {0} is set to Private. <br/>DesuraTools works only with public Desura Profiles." .format(self.current_profileid)).exec_() return except gameslist.NoSuchProfileError: self.logger.error( "Failed to load games - Desura account not found") self.statusBar.showMessage( "Failed to load games - Desura account not found") return except gameslist.InvalidDesuraProfileError: self.logger.error( "Failed to load games - Desura Profile ID invalid") self.ownedGames_list.customContextMenuRequested.connect( self.show_game_context) self.ownedGames_list.doubleClicked.connect(self.install_game) self.statusBar.showMessage( "All owned Desura games loaded for account {0}".format( gameslist.username_from_profile_id(self.current_profileid))) self.logger.info( "All owned Desura games loaded for Desura profile id {0}".format( self.current_profileid)) def set_current_account(self, profileid=None): if profileid is None: profileid = self.desuraAccountName_input.text() if not self.verify_user(profileid): return False try: gameslist.GamesList(profileid) except gameslist.InvalidDesuraProfileError: raise self.current_profileid = profileid self.logger.info("Set current profileid to {0}".format( self.current_profileid)) self.setWindowTitle("DesuraTools - {0}".format( gameslist.username_from_profile_id(self.current_profileid))) return True def populate_installed_games(self): for game in installedgames.get_games(): self.populate_qlistwidget(game, self.installedGames_list) def swap_tabs(self): gamelist = self.get_current_list() if gamelist[1] == 0: self.installButton.setText("Add Selected to Steam") if gamelist[1] == 1: self.installButton.setText("Install Selected") self.gameIcon_label.clear() self.gameName_label.clear() self.gameShortName_label.clear() def show_game_context(self): gamelist = self.get_current_list() if gamelist[0].itemAt(gamelist[0].mapFromGlobal( QCursor.pos())) is gamelist[0].currentItem(): if gamelist[1] == 0: self.installedGames_menu.exec_(QCursor.pos()) else: self.ownedGames_menu.exec_(QCursor.pos()) def process_install_button(self): gamelist = self.get_current_list() if gamelist[1] == 1: self.install_game() if gamelist[1] == 0: self.add_to_steam() self.get_steam_manager().save() def install_game(self): self.statusBar.showMessage("Sign into Desura to install") if not self.verify_user(): self.statusBar.showMessage("Failed to verify user") return gamelist = self.get_current_list() if gamelist[1] == 1: for item in gamelist[0].selectedItems(): game = item.data(Qt.UserRole) self.logger.info(' '.join(["Installing", game.name])) self.statusBar.showMessage(' '.join(["Installing", game.name])) game.install() def uninstall_game(self): self.statusBar.showMessage("Sign into Desura to uninstall") if not self.verify_user(): self.statusBar.showMessage("Failed to verify user") return gamelist = self.get_current_list() if gamelist[1] == 0: if len(gamelist[0].selectedItems()) > 1: confirm_uninstall = user_choice( "Are you sure you want to uninstall {0} games?".format( len(gamelist[0].selectedItems())), "Confirm batch uninstallation", QMessageBox.Information, acceptbutton="Uninstall") result = confirm_uninstall.exec_() if result is not QMessageBox.AcceptRole: self.logger.info("Uninstall {0} games canceled".format( len(gamelist[0].selectedItems()))) self.statusBar.showMessage( "Uninstall {0} games canceled".format( len(gamelist[0].selectedItems()))) return for item in gamelist[0].selectedItems(): game = item.data(Qt.UserRole) self.logger.info(' '.join(["Uninstalling", game.name])) self.statusBar.showMessage(' '.join( ["Uninstalling", game.name])) game.uninstall() def verify_game(self): self.statusBar.showMessage("Sign into Desura to verify") if not self.verify_user(): self.statusBar.showMessage("Failed to verify user") return gamelist = self.get_current_list() if gamelist[1] == 0: for item in gamelist[0].selectedItems(): game = item.data(Qt.UserRole) self.logger.info(' '.join(["Verifying", game.name])) self.statusBar.showMessage(' '.join(["Verifying", game.name])) game.verify() def add_to_steam(self): if not self.check_if_steam_running(): return gamelist = self.get_current_list() if gamelist[1] == 0: for item in gamelist[0].selectedItems(): game = item.data(Qt.UserRole) if 'ID64:' in self.steamID_input.currentText(): steamid = long(self.steamID_input.currentText().replace( 'ID64:', '')) else: steamid = steam_user_manager.communityid64_from_name( self.steamID_input.currentText()) QApplication.processEvents() if not steamutils.check_steam_version(steamid, game.name): if not steamutils.shortcut_exists(self.get_steam_manager(), game.name): steamutils.insert_shortcut(self.get_steam_manager(), game.name, game.exe, icons.choose_icon(game)) self.statusBar.showMessage( "Added {0} to the Steam library".format(game.name)) QApplication.processEvents() else: self.statusBar.showMessage( "{0} already exists in the Steam library".format( game.name)) QApplication.processEvents() else: self.statusBar.showMessage( "Steam account {0} already owns the Steam version of {1}" .format(self.steamID_input.currentText(), game.name)) QApplication.processEvents() def get_steam_manager(self): steamid = steam_user_manager.communityid32_from_name( self.steamID_input.currentText()) vdf = steam_user_manager.shortcuts_file_for_user_id(steamid) return steam_shortcut_manager.SteamShortcutManager(vdf) def update_gameinfo(self): gamelist = self.get_current_list() if len(gamelist[0].selectedItems()) == 1: game = gamelist[0].currentItem().data(Qt.UserRole) self.gameName_label.setText(game.name) self.gameShortName_label.setText(game.shortname) if gamelist[1] == 0: self.gameIcon_label.setPixmap(QPixmap(game.icon)) if gamelist[1] == 1: self.gameIcon_label.setPixmap(self.qpixmap_from_url(game.icon)) else: self.gameName_label.setText("{0} Items Selected".format( str(len(gamelist[0].selectedItems())))) self.gameIcon_label.clear() self.gameShortName_label.clear() def refresh_list(self): gamelist = self.get_current_list() gamelist[0].clear() if gamelist[1] == 0: self.populate_installed_games() if gamelist[1] == 1: self.populate_owned_games() def refresh_all(self): self.installedGames_list.clear() self.ownedGames_list.clear() self.populate_installed_games() self.populate_owned_games() def select_all_games(self): self.get_current_list()[0].selectAll() def open_desura_page(self): gamelist = self.get_current_list() for item in gamelist[0].selectedItems(): game = item.data(Qt.UserRole) game.storepage() def get_current_list(self): if self.tabWidget.currentIndex() == 0: return self.installedGames_list, 0 if self.tabWidget.currentIndex() == 1: return self.ownedGames_list, 1 def check_if_steam_running(self): if windows.steam_running(): self.statusBar.showMessage("Steam is currently running") ask_close_steam = user_choice( "<b>Steam is currently running</b><br />Please close Steam before adding a game", "Close Steam before continuing", QMessageBox.Warning, acceptbutton="Close Steam") result = ask_close_steam.exec_() if result == QMessageBox.AcceptRole: self.logger.info("Waiting for Steam to close") self.statusBar.showMessage( "Waiting for Steam to close.. Please wait") windows.close_steam() return True else: self.logger.error( "Could not add game to Steam - Steam still running") self.statusBar.showMessage( "Could not add game to Steam - Steam still running") return False else: return True def generate_report(self): if len(self.current_profileid) == 0: self.statusBar.showMessage("Please enter your Desura username") return self.logger.info("Generating Report") self.statusBar.showMessage("Generating Report") webbrowser.open(str(DesuraReport(self.current_profileid))) def action_factory(self, text, connect): action = QAction(text, self) action.activated.connect(connect) return action @staticmethod def qpixmap_from_url(url): img_data = urllib.urlopen(url).read() itemicon = QPixmap() itemicon.loadFromData(img_data) return itemicon
class ActivityStatus(QMainWindow): """ Main application window, responsible for application lifecycle """ def __init__(self): QMainWindow.__init__(self, None, Qt.FramelessWindowHint) self.__settings = Settings() self.__activityManager = ActivityManager(self.__settings) self.__trayIcon = QSystemTrayIcon(self) self.__managerController = ActivityManagerControl(self, self.__activityManager) self.__appMenu = QMenu(self) self.__closeAction = QAction(self.tr('Close'), self) self.__appIcon = resources.getIcon('pomidor.png') self._configureActions() self._configureMenu() self._setupTrayIcon() self._configureMainWindow() self._setupEventHooks() logging.debug('Application started') def _setupTrayIcon(self): """ Set initial image on tray icon """ self.__trayIcon.setIcon(self.__appIcon) self.__trayIcon.show() self.__trayIcon.activated.connect(self._trayIconClicked) self.__trayIcon.setContextMenu(self.__appMenu) def _configureMainWindow(self): """Configure main window contents""" self.setCentralWidget(self.__managerController) self.setWindowIcon(self.__appIcon) def _setupEventHooks(self): """Connect to event hooks provided by the activity manager""" self.__activityManager.activityStarted += self._hideMainWindow self.__activityManager.workActivityEnded += self._notifyActivityEnding self.__activityManager.breakActivityEnded += self._notifyActivityEnding self.__activityManager.activityTimeChanged += self._showRemainingTime def _configureMenu(self): """Configure application menu, add all actions and separators""" self.__appMenu.addActions(self.__managerController.actionList) self.__appMenu.addSeparator() self.__appMenu.addAction(self.__closeAction) def _configureActions(self): """Configure actions of the main controller""" self.__closeAction.triggered.connect(_closeApplication) def _trayIconClicked(self, reason): """ Process the click on the tray icon @param reason: how the icon was clicked """ logging.debug('Tray icon clicked') if reason == QSystemTrayIcon.Trigger: if self.isVisible(): self._hideMainWindow() else: self._showMainWindw() def closeEvent(self, event): """ Prevent main window from closing by clicking on close button @param event: the event, which controls the operation @type event: QCloseEvent """ event.ignore() self._hideMainWindow() def _hideMainWindow(self, _=''): """Hide main window from the screen""" logging.debug('Main window is hidden') self.setVisible(False) def _showMainWindw(self): """Show main window near-by to the system tray icon""" logging.debug('Main window is shown') self.setVisible(True) trayIconGeometry = self.__trayIcon.geometry() screenGeometry = QApplication.desktop().screenGeometry(trayIconGeometry.topLeft()) self.move(_calculateWindowPosition(screenGeometry, trayIconGeometry, self.width(), self.height())) def _notifyActivityEnding(self): """Invoke activity ending action""" logging.debug('Notifying user about action ending') process = Process(target=_executeAction, args=(self.__settings.endActivityAction,)) process.start() self.__trayIcon.setIcon(self.__appIcon) def _showRemainingTime(self, seconds): """ Show remaining time to the user @param seconds: remaining time @type seconds: int """ if seconds > 60: time = int(seconds / 60) else: time = seconds text = "{0:02d}".format(time) basePixelMap = resources.getPixelMap('pomidor.png') painter = QPainter(basePixelMap) painter.setFont(QFont("PT Sans", 64, QFont.Bold)) painter.setPen(QPen(QColor(0, 0, 0))) painter.drawText(basePixelMap.rect(), Qt.AlignCenter, text) painter.setFont(QFont("PT Sans", 58, QFont.Bold)) painter.setPen(QPen(QColor(240, 240, 240))) painter.drawText(basePixelMap.rect(), Qt.AlignCenter, text) painter.end() self.__trayIcon.setIcon(QIcon(basePixelMap))
class MainWindow(QMainWindow, Ui_MainWindow): def __init__(self, parent=None): super(MainWindow, self).__init__(parent) self.current_profileid = "" self.setupUi(self) self.logger = get_logger('desuratools', 'desuratools.log') self.logger.info('Logger Created') boldfont = QApplication.font() boldfont.setBold(True) self.addToSteam_action = self.action_factory("Add to Steam", self.add_to_steam) self.addToSteam_action.setFont(boldfont) self.installGame_action = self.action_factory("Install", self.install_game) self.installGame_action.setFont(boldfont) self.desuraPage_action = self.action_factory("View Profile", self.open_desura_page) self.uninstallGame_action = self.action_factory("Uninstall", self.uninstall_game) self.verifyGame_action = self.action_factory("Verify", self.verify_game) self.ownedGames_menu = QMenu(self) self.ownedGames_menu.addActions([ self.installGame_action, self.desuraPage_action ]) self.installedGames_menu = QMenu(self) self.installedGames_menu.addActions([ self.addToSteam_action, self.desuraPage_action, self.uninstallGame_action, self.verifyGame_action ]) self.selectAllButton.clicked.connect(self.select_all_games) self.desuraAccountName_verify.clicked.connect(self.populate_owned_games) self.installButton.clicked.connect(self.process_install_button) self.generateDesuraReport_action.activated.connect(self.generate_report) self.tabWidget.currentChanged.connect(self.swap_tabs) self.ownedGames_list.itemSelectionChanged.connect(self.update_gameinfo) self.installedGames_list.itemSelectionChanged.connect(self.update_gameinfo) self.refreshButton.clicked.connect(self.refresh_list) self.refreshLists_action.activated.connect(self.refresh_all) self.installedGames_list.customContextMenuRequested.connect(self.show_game_context) self.installedGames_list.doubleClicked.connect(self.add_to_steam) self.installedGames_list.setSelectionMode(QAbstractItemView.ExtendedSelection) self.ownedGames_list.setSelectionMode(QAbstractItemView.ExtendedSelection) self.steamID_input.addItems(steamutils.get_customurls_on_machine()) self.ownedGames_list.addItem("Verify your Desura username to see your owned games") QApplication.processEvents() self.loading_dialog = ProgressBarDialog() self.loading_dialog.show() QApplication.processEvents() self.populate_installed_games() self.load_data() self.loading_dialog.close() self.raise_() def verify_user(self, profileid=None): if profileid is None: profileid=self.current_profileid if len(profileid) == 0: return False try: username = gameslist.username_from_profile_id(profileid) except gameslist.NoSuchProfileError: return False if windows.desura_running(username): return True verify_dialog = QMessageBox() verify_dialog.setText("<b>Verify your identity</b><br />Sign in to Desura to continue with account <b>{0}</b> to confirm your identity".format(username)) verify_dialog.setInformativeText("<i>Waiting for Desura sign-in...</i>") verify_dialog.setWindowTitle("Sign into Desura to continue") verify_dialog.setStandardButtons(QMessageBox.Cancel) verify_dialog.setIcon(QMessageBox.Information) verify_dialog.setWindowFlags(Qt.CustomizeWindowHint | Qt.WindowTitleHint) desurawaiter = DesuraWaiter(username) desurawaiter.finished.connect(verify_dialog.close) desurawaiter.start() verify_dialog.exec_() if windows.desura_running(username): return True else: desurawaiter.terminate() return False def load_data(self): try: with open(os.path.join(windows.data_dir(), 'desuratools.json'), 'r') as savefile: try: data = json.loads(savefile.read()) except Exception: self.desuraAccountName_input.setText("") return self.desuraAccountName_input.setText(data['desuraname']) if data['desuraname'] != "": self.populate_owned_games() steamid = self.steamID_input.findText(data['steamname']) self.steamID_input.setCurrentIndex(steamid) except IOError: pass def closeEvent(self, *args, **kwargs): self.logger.info("Saving to file") savefile = open(os.path.join(windows.data_dir(), 'desuratools.json'), 'w') savefile.write( json.dumps({ 'desuraname': self.current_profileid, 'steamname': self.steamID_input.currentText() }) ) savefile.close() QApplication.quit() def populate_qlistwidget(self, game, qlistwidget, iconurls=False): if iconurls: itemicon = self.qpixmap_from_url(game.icon) QApplication.processEvents() else: itemicon = QPixmap(game.icon) QApplication.processEvents() item = QListWidgetItem(itemicon, game.name, qlistwidget) item.setData(Qt.UserRole, game) qlistwidget.addItem(item) def populate_owned_games(self): self.statusBar.showMessage("Waiting for Desura... Please Wait") try: if not self.set_current_account(): if len(self.desuraAccountName_input.text()) > 0: self.statusBar.showMessage("Invalid Desura Account") else: self.statusBar.showMessage("") return self.ownedGames_list.clear() self.loading_dialog.setAccount(gameslist.username_from_profile_id(self.current_profileid)) QApplication.processEvents() self.loading_dialog.setMaximum(len(gameslist.GamesList(self.current_profileid).get_games())) QApplication.processEvents() for game in gameslist.GamesList(self.current_profileid).get_games(): self.populate_qlistwidget(game, self.ownedGames_list, True) QApplication.processEvents() self.loading_dialog.increment(1, game.name) QApplication.processEvents() self.logger.info("Added Game {0}".format(game.name)) self.statusBar.showMessage("Added Game {0}".format(game.name)) except gameslist.PrivateProfileError: self.logger.error("Failed to load games - Private Desura Profile") self.statusBar.showMessage("Failed to load games - Private Desura Profiles not supported") error_message( "The Desura Profile {0} is set to Private. <br/>DesuraTools works only with public Desura Profiles." .format(self.current_profileid) ).exec_() return except gameslist.NoSuchProfileError: self.logger.error("Failed to load games - Desura account not found") self.statusBar.showMessage("Failed to load games - Desura account not found") return except gameslist.InvalidDesuraProfileError: self.logger.error("Failed to load games - Desura Profile ID invalid") self.ownedGames_list.customContextMenuRequested.connect(self.show_game_context) self.ownedGames_list.doubleClicked.connect(self.install_game) self.statusBar.showMessage("All owned Desura games loaded for account {0}".format( gameslist.username_from_profile_id(self.current_profileid)) ) self.logger.info("All owned Desura games loaded for Desura profile id {0}".format(self.current_profileid)) def set_current_account(self, profileid=None): if profileid is None: profileid = self.desuraAccountName_input.text() if not self.verify_user(profileid): return False try: gameslist.GamesList(profileid) except gameslist.InvalidDesuraProfileError: raise self.current_profileid = profileid self.logger.info("Set current profileid to {0}".format(self.current_profileid)) self.setWindowTitle("DesuraTools - {0}".format(gameslist.username_from_profile_id(self.current_profileid))) return True def populate_installed_games(self): for game in installedgames.get_games(): self.populate_qlistwidget(game, self.installedGames_list) def swap_tabs(self): gamelist = self.get_current_list() if gamelist[1] == 0: self.installButton.setText("Add Selected to Steam") if gamelist[1] == 1: self.installButton.setText("Install Selected") self.gameIcon_label.clear() self.gameName_label.clear() self.gameShortName_label.clear() def show_game_context(self): gamelist = self.get_current_list() if gamelist[0].itemAt(gamelist[0].mapFromGlobal(QCursor.pos())) is gamelist[0].currentItem(): if gamelist[1] == 0: self.installedGames_menu.exec_(QCursor.pos()) else: self.ownedGames_menu.exec_(QCursor.pos()) def process_install_button(self): gamelist = self.get_current_list() if gamelist[1] == 1: self.install_game() if gamelist[1] == 0: self.add_to_steam() self.get_steam_manager().save() def install_game(self): self.statusBar.showMessage("Sign into Desura to install") if not self.verify_user(): self.statusBar.showMessage("Failed to verify user") return gamelist = self.get_current_list() if gamelist[1] == 1: for item in gamelist[0].selectedItems(): game = item.data(Qt.UserRole) self.logger.info(' '.join(["Installing", game.name])) self.statusBar.showMessage(' '.join(["Installing", game.name])) game.install() def uninstall_game(self): self.statusBar.showMessage("Sign into Desura to uninstall") if not self.verify_user(): self.statusBar.showMessage("Failed to verify user") return gamelist = self.get_current_list() if gamelist[1] == 0: if len(gamelist[0].selectedItems()) > 1: confirm_uninstall = user_choice( "Are you sure you want to uninstall {0} games?".format(len(gamelist[0].selectedItems())), "Confirm batch uninstallation", QMessageBox.Information, acceptbutton="Uninstall" ) result = confirm_uninstall.exec_() if result is not QMessageBox.AcceptRole: self.logger.info("Uninstall {0} games canceled".format(len(gamelist[0].selectedItems()))) self.statusBar.showMessage("Uninstall {0} games canceled".format(len(gamelist[0].selectedItems()))) return for item in gamelist[0].selectedItems(): game = item.data(Qt.UserRole) self.logger.info(' '.join(["Uninstalling", game.name])) self.statusBar.showMessage(' '.join(["Uninstalling", game.name])) game.uninstall() def verify_game(self): self.statusBar.showMessage("Sign into Desura to verify") if not self.verify_user(): self.statusBar.showMessage("Failed to verify user") return gamelist = self.get_current_list() if gamelist[1] == 0: for item in gamelist[0].selectedItems(): game = item.data(Qt.UserRole) self.logger.info(' '.join(["Verifying", game.name])) self.statusBar.showMessage(' '.join(["Verifying", game.name])) game.verify() def add_to_steam(self): if not self.check_if_steam_running(): return gamelist = self.get_current_list() if gamelist[1] == 0: for item in gamelist[0].selectedItems(): game = item.data(Qt.UserRole) if 'ID64:' in self.steamID_input.currentText(): steamid = long(self.steamID_input.currentText().replace('ID64:', '')) else: steamid = steam_user_manager.communityid64_from_name(self.steamID_input.currentText()) QApplication.processEvents() if not steamutils.check_steam_version(steamid, game.name): if not steamutils.shortcut_exists(self.get_steam_manager(), game.name): steamutils.insert_shortcut(self.get_steam_manager(), game.name, game.exe, icons.choose_icon(game)) self.statusBar.showMessage("Added {0} to the Steam library".format(game.name)) QApplication.processEvents() else: self.statusBar.showMessage("{0} already exists in the Steam library".format(game.name)) QApplication.processEvents() else: self.statusBar.showMessage("Steam account {0} already owns the Steam version of {1}".format( self.steamID_input.currentText(), game.name) ) QApplication.processEvents() def get_steam_manager(self): steamid = steam_user_manager.communityid32_from_name(self.steamID_input.currentText()) vdf = steam_user_manager.shortcuts_file_for_user_id(steamid) return steam_shortcut_manager.SteamShortcutManager(vdf) def update_gameinfo(self): gamelist = self.get_current_list() if len(gamelist[0].selectedItems()) == 1: game = gamelist[0].currentItem().data(Qt.UserRole) self.gameName_label.setText(game.name) self.gameShortName_label.setText(game.shortname) if gamelist[1] == 0: self.gameIcon_label.setPixmap(QPixmap(game.icon)) if gamelist[1] == 1: self.gameIcon_label.setPixmap(self.qpixmap_from_url(game.icon)) else: self.gameName_label.setText("{0} Items Selected".format(str(len(gamelist[0].selectedItems())))) self.gameIcon_label.clear() self.gameShortName_label.clear() def refresh_list(self): gamelist = self.get_current_list() gamelist[0].clear() if gamelist[1] == 0: self.populate_installed_games() if gamelist[1] == 1: self.populate_owned_games() def refresh_all(self): self.installedGames_list.clear() self.ownedGames_list.clear() self.populate_installed_games() self.populate_owned_games() def select_all_games(self): self.get_current_list()[0].selectAll() def open_desura_page(self): gamelist = self.get_current_list() for item in gamelist[0].selectedItems(): game = item.data(Qt.UserRole) game.storepage() def get_current_list(self): if self.tabWidget.currentIndex() == 0: return self.installedGames_list, 0 if self.tabWidget.currentIndex() == 1: return self.ownedGames_list, 1 def check_if_steam_running(self): if windows.steam_running(): self.statusBar.showMessage("Steam is currently running") ask_close_steam = user_choice( "<b>Steam is currently running</b><br />Please close Steam before adding a game", "Close Steam before continuing", QMessageBox.Warning, acceptbutton="Close Steam" ) result = ask_close_steam.exec_() if result == QMessageBox.AcceptRole: self.logger.info("Waiting for Steam to close") self.statusBar.showMessage("Waiting for Steam to close.. Please wait") windows.close_steam() return True else: self.logger.error("Could not add game to Steam - Steam still running") self.statusBar.showMessage("Could not add game to Steam - Steam still running") return False else: return True def generate_report(self): if len(self.current_profileid) == 0: self.statusBar.showMessage("Please enter your Desura username") return self.logger.info("Generating Report") self.statusBar.showMessage("Generating Report") webbrowser.open(str(DesuraReport(self.current_profileid))) def action_factory(self, text, connect): action = QAction(text, self) action.activated.connect(connect) return action @staticmethod def qpixmap_from_url(url): img_data = urllib.urlopen(url).read() itemicon = QPixmap() itemicon.loadFromData(img_data) return itemicon