def __init__(self, parent=None): QtGui.QWidget.__init__(self, parent) self.ui = Ui_MigrationUI() self.ui.setupUi(self) for s in availableScreens: print "SCREEN: ", s self.screens = availableScreens # filter(lambda s: s != None, availableScreens) #edited # print self.screens self.moveInc = 1 self.menuText = "" # self.config = KConfig("migrationrc") self.createWidget(self.screens) self.screenId = [] for each in self.screens: title = each.Widget().title title = i18n(title) self.screenId.append(title) if self.screens.index(each) == 0: self.menuText += self.putBold(title) else: self.menuText += self.putBr(title) self.ui.labelMenu.setText(self.menuText) QtCore.QObject.connect(self.ui.buttonNext, QtCore.SIGNAL("clicked()"), self.slotNext) QtCore.QObject.connect(self.ui.buttonBack, QtCore.SIGNAL("clicked()"), self.slotBack) QtCore.QObject.connect(self.ui.buttonFinish, QtCore.SIGNAL("clicked()"), QtGui.qApp, QtCore.SLOT("quit()")) QtCore.QObject.connect(self.ui.buttonCancel, QtCore.SIGNAL("clicked()"), QtGui.qApp, QtCore.SLOT("quit()"))
def shown(self): subject = "<p><li><b>%s</b></li><ul>" item = "<li>%s</li>" end = "</ul></p>" content = QString("") content.append("""<html><body><ul>""") # Selected User content.append(subject % i18n("User Settings")) content.append(item % i18n("Selected User: <b>%s</b>") % ctx.user[2]) content.append(end) # Selected Options content.append(subject % i18n("Options Settings")) for key,value in ctx.options.items(): print "YOOO:", key, value content.append(item % i18n("Option %1 : <b>%2</b>", key, value)) content.append(end) if ctx.filesOptions: #Selected Files Destinations content.append(subject % i18n("Destination Settings")) if ctx.filesOptions.has_key("links"): for link in ctx.filesOptions["links"]: content.append(item % i18n("Linked Destination to: <b> %s </b>") % link) elif ctx.filesOptions.has_key("copy destination"): content.append(item % i18n("Copied Destination to: <b> %s </b>") % ctx.filesOptions["copy destination"]) content.append(end) content.append("""</ul></body></html>""") self.ui.textSummary.setHtml(content)
def execute(self): if ctx.user: part, ostype, username, userdir = ctx.user sources = {"Partition":part, "OS Type":ostype, "User Name":username, "Home Path":userdir} ctx.sources = info.userInfo(sources) ctx.destinations = info.localInfo() return (True, None) else: return (False, i18n("There isn't any selected user on User Selection Window!"))
def __init__(self, parent): QtGui.QWidget.__init__(self, parent) #self.vbox = QtGui.QVBoxLayout(self) self.layout = QtGui.QGridLayout(self) # Top Label: self.label = QtGui.QLabel(self) self.label.setText(i18n("Please wait while applying changes...")) #self.label.setAlignment(Qt.AlignLeft) self.layout.addWidget(self.label, 0, 0) # Progress Bar Grid Layout: #self.progresslayout = QtGui.QGridLayout(self) #self.vbox.addLayout(self.progresslayout) # Progress 1: self.label1 = QtGui.QLabel(self) self.label1.setText(i18n("Prepare: ")) self.layout.addWidget(self.label1, 1, 0) self.progressbar1 = QtGui.QProgressBar(self) self.layout.addWidget(self.progressbar1, 1, 1) # Progress 2: self.label2 = QtGui.QLabel(self) self.label2.setText(i18n("Apply: ")) self.layout.addWidget(self.label2, 2, 0) self.progressbar2 = QtGui.QProgressBar(self) self.layout.addWidget(self.progressbar2, 2, 1) # Operation Lines: #self.operationlines = QtGui.QVBoxLayout() #self.layout.addLayout(self.operationlines,) spacer = QtGui.QSpacerItem(5, 5, QtGui.QSizePolicy.Minimum, QtGui.QSizePolicy.Expanding) self.layout.addItem(spacer) self.progressLayout = QtGui.QVBoxLayout() self.layout.addLayout(self.progressLayout, 3, 0) # Progress Variables: self.steps1 = 0 self.steps2 = 0 self.progress1 = 0 self.progress2 = 0 self.active = 0 self.operations = [] self.updateProgress()
def copyItem(src, dst, progress): basename = os.path.basename(dst) dirname = os.path.dirname(dst) if basename in ignoreList: return if not os.path.exists(dirname): os.makedirs(dirname) if os.path.isfile(src): try: shutil.copy2(src, dst) except: progress.go(unicode(i18n("file '%s' could not be copied")) % unicode(src), ctx.WARNING, os.path.getsize(src)) else: progress.go(unicode(i18n("file '%s' copied")) % unicode(src), ctx.OK, os.path.getsize(src)) elif os.path.isdir(src): if not os.path.exists(dst): os.makedirs(dst) files = os.listdir(src) for item in files: newdst = os.path.join(dst, item) newsrc = os.path.join(src, item) copyItem(newsrc, newdst, progress)
def creator(self, sources): # Add folders: folders = [] acceptList = [("Personal Path", "My Documents", i18n("My Documents")), ("Desktop Path", "Desktop", i18n("Desktop")), ("My Music Path", "My Music", i18n("My Music")), ("My Pictures Path", "My Pictures", i18n("My Pictures")), ("My Video Path", "My Video", i18n("My Video"))] for key, name, localname in acceptList: if sources.has_key(key): path = sources[key] folders.append((path, name, unicode(localname))) # Check if one dir includes another: for index, (path, name, localname) in enumerate(folders): unique = True for index2, (path2, name2, localname2) in enumerate(folders): # If this is a child, skip if path.find(path2) == 0 and index != index2: unique = False break if unique: DirectoryViewRoot(self.ui.dirview, path, name, localname)
def addKMailMessages(self, progress=None): # Information message: infomessagepath = os.path.join(tempfile.gettempdir(), "temp_kmail_info.eml") message = "From:pardus@localhost\r\nSubject:%s\r\n\r\n%s" % (i18n("Migrated Folder"), i18n("This messagebox is migrated using Pardus Migration Tool")) messagefile = open(infomessagepath, "w") messagefile.write(message) messagefile.close() kmail = connectKMail() # Loop over folders: for (name, path) in self.folders[2:]: # Add Info Message: #addMessage(name, infomessagepath, kmail) # Chech Message Box Type if os.path.isfile(path): # Copy mbox: box = MBox(path) boxsize = os.path.getsize(path) totalsize = 0 messagepath = box.next() while messagepath: try: addMessage(name, messagepath, kmail) except DuplicateMessage, text: totalsize += os.path.getsize(messagepath) progress.go(None, progress.OK, os.path.getsize(messagepath)) except DBUSError, text: progress.go(text, progress.WARNING, 0) kmail = connectKMail() continue except MailError, text: totalsize += os.path.getsize(messagepath) progress.go(text, progress.WARNING, os.path.getsize(messagepath)) else: totalsize += os.path.getsize(messagepath) progress.go(None, progress.OK, os.path.getsize(messagepath)) messagepath = box.next()
def creator(self, sources): # Wallpaper: if sources.has_key("Wallpaper Path"): self.wallpaperGroup = QtGui.QButtonGroup(self) self.wallpaperLayout = QtGui.QHBoxLayout(self.wallpaperGroup) self.box.addWidget(self.wallpaperGroup) # New (current) Wallpaper: self.newLayout = QtGui.QVBoxLayout(None) #self.newLayout.setAlignment(Qt.AlignCenter) self.wallpaperLayout.addLayout(self.newLayout) # Thumbnail: self.newThumb = QtGui.QLabel(self.wallpaperGroup) self.newLayout.addWidget(self.newThumb) if destinations.has_key("Wallpaper Path"): newwp = QtGui.QImage(unicode(destinations["Wallpaper Path"])) newwp = newwp.smoothScale(100, 100, QImage.ScaleMax) pixmap = QtGui.QPixmap(newwp) self.newThumb.setPixmap(pixmap) # Radio Button: self.newRadio = QtGui.QRadioButton(self.wallpaperGroup) if destinations.has_key("Wallpaper Path"): self.newRadio.setText(i18n("Keep current wallpaper")) else: self.newRadio.setText(i18n("Don't use wallpaper")) self.newRadio.setToolTip(i18n("Does not change your wallpaper.")) self.newRadio.setChecked(True) self.newLayout.addWidget(self.newRadio) # Old Wallpaper: self.oldLayout = QtGui.QVBoxLayout(None) #self.oldLayout.setAlignment(Qt.AlignCenter) self.wallpaperLayout.addLayout(self.oldLayout) # Thumbnail: self.oldThumb = QtGui.QLabel(self.wallpaperGroup) oldwp = QtGui.QImage(unicode(sources["Wallpaper Path"])) oldwp = oldwp.smoothScale(100, 100, QImage.ScaleMax) pixmap = QtGui.QPixmap(oldwp) self.oldThumb.setPixmap(pixmap) self.oldLayout.addWidget(self.oldThumb) # Radio Button: self.oldRadio = QtGui.QRadioButton(self.wallpaperGroup) self.oldRadio.setObjectName("oldRadio") self.oldRadio.setText(i18n("Use my old wallpaper")) self.oldRadio.setToolTip(i18n("Copies your old wallpaper to Pardus and sets it as new background image.")) self.oldLayout.addWidget(self.oldRadio) # Bookmarks: if sources.has_key("Firefox Profile Path") or sources.has_key("Favorites Path"): self.bookmarks = QtGui.QGroupBox("Bookmarks", self) self.bookmarks.setTitle(i18n("Bookmarks")) self.bookmarks.setAlignment(Qt.AlignLeft) self.bookmarksLayout = QtGui.QVBoxLayout(self.bookmarks) self.box.addWidget(self.bookmarks) self.box.addWidget(self.bookmarks) # FF Bookmarks: if sources.has_key("Firefox Profile Path"): self.fireFoxBookmarks = QtGui.QCheckBox(self.bookmarks) self.fireFoxBookmarks.setObjectName("FFBookmarks") self.fireFoxBookmarks.setText(i18n("Firefox Bookmarks")) self.fireFoxBookmarks.setChecked(True) self.fireFoxBookmarks.setToolTip(i18n("Copies your old Firefox bookmarks to Firefox under Pardus.")) self.bookmarksLayout.addWidget(self.fireFoxBookmarks) # Opera Bookmarks: if sources.has_key("Opera Profile Path"): self.operaBookmarks = QCheckBox(self.bookmarks) self.operaBookmarks.setObjectName("OperaBookmarks") self.operaBookmarks.setText(i18n("Opera Bookmarks")) self.operaBookmarks.setChecked(True) self.operaBookmarks.setToolTip(i18n("Copies your old Opera bookmarks to Firefox under Pardus.")) self.bookmarksLayout.addWidget(self.operaBookmarks) # IE Bookmarks: if sources.has_key("Favorites Path"): self.IEBookmarks = QtGui.QCheckBox(self.bookmarks) self.IEBookmarks.setObjectName("IEBookmarks") self.IEBookmarks.setText(i18n("Internet Explorer favorites")) self.IEBookmarks.setChecked(True) self.IEBookmarks.setToolTip(i18n("Copies your old Internet Explorer favorites to Firefox under Pardus.")) self.bookmarksLayout.addWidget(self.IEBookmarks) # Mail Accounts: if sources.has_key("Windows Mail Path") or sources.has_key("Thunderbird Profile Path"): self.mailAccounts = QtGui.QGroupBox("MailAccounts", self) self.mailAccounts.setTitle(i18n("E-Mail and News Accounts")) self.mailAccounts.setAlignment(Qt.AlignLeft) self.mailAccountsLayout = QtGui.QVBoxLayout(self.mailAccounts) self.box.addWidget(self.mailAccounts) # Windows Mail Accounts: if sources.has_key("Windows Mail Path"): self.winMail = QtGui.QCheckBox(self.mailAccounts) self.winMail.setObjectName("WinMail") self.winMail.setText(i18n("Windows Mail accounts")) self.winMail.setChecked(True) self.winMail.setToolTip(i18n("Copies your old mail and newsgroup accounts to KMail and KNode applications.")) self.mailAccountsLayout.addWidget(self.winMail) # Thunderbird Accounts: if sources.has_key("Thunderbird Profile Path"): self.TB = QtGui.QCheckBox(self.mailAccounts) self.TB.setObjectName("TB") self.TB.setText(i18n("Thunderbird accounts")) self.TB.setChecked(True) self.TB.setToolTip(i18n("Copies your old mail and newsgroup accounts to KMail and KNode applications.")) self.mailAccountsLayout.addWidget(self.TB) # E-Mails: self.mail = QtGui.QCheckBox(self.mailAccounts) self.mail.setObjectName("mail") self.mail.setText(i18n("Copy e-mail messages from e-mail accounts")) self.mail.setChecked(True) self.mail.setToolTip(i18n("Copies your e-mail messages to KMail from selected applications above.")) self.mailAccountsLayout.addWidget(self.mail) # IM Accounts: if sources.has_key("Contacts Path") or sources.has_key("GTalk Key"): self.IMAccounts = QtGui.QGroupBox("IMAccounts", self) self.IMAccounts.setTitle(i18n("Instant Messenger Accounts")) self.IMAccounts.self.IMAccounts.layout() self.IMAccountsLayout = QVBoxLayout(self.IMAccounts) self.vbox.addWidget(self.IMAccounts) # MSN Accounts: if sources.has_key("Contacts Path"): self.MSN = QtGui.QCheckBox(self.IMAccounts) self.MSN.setObjectName("MSN") self.MSN.setText(i18n("MSN accounts")) self.MSN.setChecked(True) self.MSN.setToolTip(i18n("Copies your MSN Messenger accounts to Kopete.")) self.IMAccountsLayout.addWidget(self.MSN) # GTalk Accounts: if sources.has_key("GTalk Key"): self.GTalk = QtGui.QCheckBox(self.IMAccounts) self.GTalk.setObjectName("GTalk") self.GTalk.setText(i18n("GTalk accounts")) self.GTalk.setChecked(True) self.GTalk.setToolTip(i18n("Copies your GTalk accounts to Kopete.")) self.IMAccountsLayout.addWidget(self.GTalk) self.IMAccounts.addLayout(self.IMAccountsLayout) # Spacer: spacer = QtGui.QSpacerItem(1,1, QtGui.QSizePolicy.Minimum, QtGui.QSizePolicy.Expanding) self.box.addItem(spacer)
messagepath = box.next() while messagepath: try: addMessage(name, messagepath, kmail) except DuplicateMessage, text: progress.go(None, progress.OK, os.path.getsize(messagepath)) except DBusException, text: progress.go(text, progress.WARNING, 0) kmail = connectKMail() continue except MailError, text: progress.go(text, progress.WARNING, os.path.getsize(messagepath)) else: progress.go(None, progress.OK, os.path.getsize(messagepath)) messagepath = box.next() progress.go(unicode(i18n("Message Box %s copied")) % name, progress.OK, 0) def setKNodeAccounts(self): for account in self.accounts: if account["type"] == "NNTP": files = os.listdir(os.path.expanduser("~/.kde/share/apps/knode")) accountid = 1 while "nntp." + str(accountid) in files: accountid += 1 dirname = os.path.expanduser("~/.kde/share/apps/knode/nntp." + str(accountid)) os.mkdir(dirname) infofile = open(os.path.join(dirname, "info"), "w") infofile.write("id=%d\n" % accountid) fields = {"host":"server", "name":"name", "email":"Email", "realname":"Name", "port":"port"} for key in fields.keys():
def run(self): if ctx.options.has_key("Wallpaper Path"): self.progresspage.addProgress(3, 1) if ctx.options.has_key("Firefox Profile Path"): self.progresspage.addProgress(10, 1) if ctx.options.has_key("Opera Profile Path"): self.progresspage.addProgress(10, 1) if ctx.options.has_key("Favorites Path"): self.progresspage.addProgress(10, 1) if ctx.options.has_key("GTalk Key"): self.progresspage.addProgress(5, 1) if ctx.options.has_key("Contacts Path"): self.progresspage.addProgress(5, 1) if ctx.options.has_key("Thunderbird Profile Path"): self.progresspage.addProgress(15, 1) if ctx.options.has_key("Windows Mail Path"): self.progresspage.addProgress(15, 1) if ctx.options.has_key("links"): self.progresspage.addProgress(3, 1) if ctx.options.has_key("folders"): self.progresspage.addProgress(20, 1) # Initialization: account = Account() bookmark = Bookmark() # Control Settings and Set Second Progress Bar: # Wallpaper: if ctx.options.has_key("Wallpaper Path"): size = os.path.getsize(ctx.options["Wallpaper Path"]) self.progresspage.addOperation(i18n("Wallpaper"), size) self.progresspage.makeProgress(3) # Firefox: if ctx.options.has_key("Firefox Profile Path"): try: bookmark.getFFBookmarks(ctx.options["Firefox Profile Path"]) except: logging.warning(i18n("Firefox bookmarks could not be loaded.")) else: logging.info(i18n("Firefox bookmarks loaded.")) self.progresspage.makeProgress(10) # Opera: if ctx.options.has_key("Opera Profile Path"): try: bookmark.getOperaBookmarks(ctx.options["Opera Profile Path"]) except: logging.warning(i18n("Opera bookmarks could not be loaded.")) else: logging.info(i18n("Opera bookmarks loaded.")) self.progresspage.makeProgress(10) # Internet Explorer: if ctx.options.has_key("Favorites Path"): try: bookmark.getIEBookmarks(ctx.options["Favorites Path"]) except: logging.warning(i18n("Internet Explorer favorites could not be loaded.")) else: logging.info(i18n("Internet Explorer favorites loaded.")) self.progresspage.makeProgress(10) # Bookmarks: size = bookmark.size() if size > 0: lockfile = os.path.join(ctx.destinations["Firefox Profile Path"], "lock") while os.path.lexists(lockfile): if warning(self.progresspage, i18n("Firefox is open. Please close it first to continue...")) == QtGui.QMessageBox.Cancel: break self.progresspage.addOperation(i18n("Bookmarks"), size) # Windows Mail: if ctx.options.has_key("Windows Mail Path"): try: account.getOEAccounts(ctx.options["Windows Mail Path"]) except: logging.warning(i18n("Windows Mail accounts could not be loaded.")) else: logging.info(i18n("Windows Mail accounts loaded.")) self.progresspage.makeProgress(15) # Thunderbird: if ctx.options.has_key("Thunderbird Profile Path"): try: account.getTBAccounts(ctx.options["Thunderbird Profile Path"]) except: logging.warning(i18n("Thunderbird accounts could be loaded.")) else: logging.info(i18n("Thunderbird accounts loaded.")) self.progresspage.makeProgress(15) # MSN Messenger Accounts: if ctx.options.has_key("Contacts Path"): try: account.getMSNAccounts(ctx.options["Contacts Path"]) except: logging.warning(i18n("MSN accounts could be loaded.")) else: logging.info(i18n("MSN accounts loaded.")) self.progresspage.makeProgress(5) # GTalk Accounts: if ctx.options.has_key("GTalk Key"): try: account.getGTalkAccounts(ctx.options["GTalk Key"]) except: logging.warning(i18n("GTalk accounts could not be loaded.")) else: logging.info(i18n("GTalk accounts loaded.")) self.progresspage.makeProgress(5) # Mail Accounts: size = account.accountSize(["POP3", "IMAP", "SMTP"]) if size > 0: # TODO: Control KMail to be closed self.progresspage.addOperation(i18n("E-Mail Accounts"), size) # E-Mails: if ctx.options.has_key("Copy E-Mails"): size = account.mailSize() if size > 0: self.progresspage.addOperation(i18n("E-Mail Messages"), size) # News Accounts: size = account.accountSize(["NNTP"]) if size > 0: # TODO: Control KNode to be closed self.progresspage.addOperation(i18n("News Accounts"), size) # IM Accounts: size = account.accountSize(["Jabber", "MSN"]) if size > 0: # TODO: Control Kopete to be closed self.progresspage.addOperation(i18n("Instant Messenger Accounts"), size) # Files: #for k,v in ctx.fileOptions.items(): #ctx.options.update(ctx.filesOptions) if ctx.filesOptions: if ctx.filesOptions.has_key("links"): self.progresspage.makeProgress(3) self.progresspage.addOperation(i18n("Desktop Links"), len(ctx.filesOptions["links"]) * 1000) if ctx.filesOptions.has_key("folders"): # Existance of directory: if not os.path.isdir(ctx.filesOptions["copy destination"]): try: os.makedirs(ctx.filesOptions["copy destination"]) except: warning(self.progresspage , unicode(i18n("Folder '%s' could not be created, please choose another folder!")) % ctx.filesOptions["copy destination"]) return # Write access: if not os.access(ctx.filesOptions["copy destination"], os.W_OK): warning(self.progresspage, unicode(i18n("You don't have permission to write to folder '%s', please choose another folder!")) % ctx.filesOptions["copy destination"]) return # File size: for folder in ctx.filesOptions["folders"]: size = files.totalSize(folder["files"]) self.progresspage.addOperation(folder["localname"], size) self.progresspage.makeProgress(20) # Control total size free = files.freeSpace(os.path.expanduser("~")) if self.progresspage.steps2 > free: arguments = {"size":self.progresspage.steps2 / 1024 / 1024, "free":free / 1024 / 1024} warning(self.progresspage, unicode(i18n("Total size of files you've selected is %(size)d MB, but you have only %(free)d MB of free space!")) % arguments) return spacerItem = QtGui.QSpacerItem(20, 40, QtGui.QSizePolicy.Minimum, QtGui.QSizePolicy.Expanding) self.progresspage.progressLayout.addItem(spacerItem) # Applying Changes: # Wallpaper: if ctx.options.has_key("Wallpaper Path"): size = os.path.getsize(ctx.options["Wallpaper Path"]) try: wall.setWallpaper(ctx.options["Wallpaper Path"]) except Exception, err: self.progresspage.go(err, ctx.ERROR, size) else: self.progresspage.go(i18n("Wallpaper changed."), ctx.OK, size)
def message(self, event): self.warning = QtGui.QMessageBox.warning(self, i18n("Warning!"), event, QtGui.QMessageBox.Ok, QtGui.QMessageBox.Cancel, QtGui.QMessageBox.NoButton)
bookmark.setFFBookmarks(ctx.destinations["Firefox Profile Path"]) except Exception, err: self.progresspage.go(err, ctx.ERROR, size) else: self.progresspage.go(i18n("Bookmarks saved."), ctx.OK, size) # Mail Accounts: size = account.accountSize(["POP3", "IMAP", "SMTP"]) if size > 0: try: account.setKMailAccounts() except Exception, err: self.progresspage.go(err, ctx.ERROR, size) else: self.progresspage.go(i18n("Mail Accounts saved."), ctx.OK, size) # E-Mails: if ctx.options.has_key("Copy E-Mails"): size = account.mailSize() if size > 0: try: account.addKMailMessages(self.progresspage) except Exception, err: self.progresspage.go(err, ctx.ERROR, size) else: self.progresspage.go(i18n("Accounts saved."), ctx.OK, 0) # News Accounts: size = account.accountSize(["NNTP"]) if size > 0:
def shown(self): if not self.users : QMessageBox.critical(self, i18n("Error"), i18n("There aren't any Microsoft Windows partitions to migrate! Please check your mounted partitions..."))