Example #1
0
class Box(QTabWidget):
    def __init__(self, parent=None):
        QTabWidget.__init__(self, parent)
        self.Parent = parent
        self.tr = Translator("Thrifty")

        self.setMovable(True)
        self.setIconSize(QSize(32, 32))

        self.checkFile = CheckFile(self)
        self.backUp = BackUp(self)
        self.cleanUp = CleanUp(self)
        self.broken = Broken(self)

        self.addTab(self.checkFile, QIcon("/usr/share/thrifty/icons/file.png"), QString(self.tr._translate("File")))
        self.setTabToolTip(0, self.tr._translate("Checks file belonging to a rpmdb"))

        self.addTab(self.backUp, QIcon("/usr/share/thrifty/icons/backup.png"), QString(self.tr._translate("BackUp")))
        self.setTabToolTip(1, self.tr._translate('Back up "rpmdb-out" files <b>(User\Root Mode)</b>.'))

        self.addTab(self.cleanUp, QIcon("/usr/share/thrifty/icons/cleanup.png"), QString(self.tr._translate("CleanUp")))
        self.setTabToolTip(2, self.tr._translate('Clean up "rpmdb-out" files <b>(Root Mode only)</b> or test.'))

        self.addTab(self.broken, QIcon("/usr/share/thrifty/icons/file.png"), QString(self.tr._translate("Broken")))
        self.setTabToolTip(3, self.tr._translate("Search broken packages <b>(Root Mode only)</b>."))

    def setTabsState(self, state):
        self.checkFile.setState(state)
        self.backUp.setState(state)
        self.cleanUp.setState(state)
        self.broken.setState(state)
        self.Parent.stopProcess.setEnabled(not state)
Example #2
0
class PageDialog(QDialog):
	okClicked = pyqtSignal()
	cancelClicked = pyqtSignal()
	settingsCancelled = pyqtSignal()
	def __init__(self, parent = None):
		QDialog.__init__(self, parent)
		self.prnt = parent
		self.tr = Translator()
		self.setWindowTitle(self.tr._translate('M@il Checker : Settings'))
		self.tabWidget = QTabWidget(self)
		self.tabWidget.setTabPosition(QTabWidget.North)
		self.layout = QVBoxLayout()
		self.buttonLayout = QHBoxLayout()
		self.ok = QPushButton(QIcon.fromTheme("dialog-ok"), "", self)
		self.cancel = QPushButton(QIcon.fromTheme("dialog-cancel"), "", self)

		self.buttonLayout.addWidget(self.ok)
		self.buttonLayout.addWidget(self.cancel)
		self.layout.addWidget(self.tabWidget)
		self.layout.addItem(self.buttonLayout)
		self.setLayout(self.layout)
		self.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)
		self.setMinimumWidth(100)
		self.ok.clicked.connect(self.accepted)
		self.cancel.clicked.connect(self.rejected)
		QTimer.singleShot(100, self._restoreGeometry)

	def _restoreGeometry(self):
		self.restoreGeometry(self.prnt.Settings.value('SettingsGeometry').toByteArray())

	def addPage(self, wdg, wdgName):
		self.tabWidget.addTab(wdg, wdgName)

	def accepted(self): self.okClicked.emit()
	def rejected(self):
		self.settingsCancelled.emit()
		self.cancelClicked.emit()

	def closeEvent(self, ev):
		ev.ignore()
		self.rejected()

	def _close(self):
		self.prnt.Settings.setValue('SettingsGeometry', self.saveGeometry())
		if not self.prnt.isVisible() :
			self.prnt.show()
			self.prnt.autoHide(3)
		if self.prnt.isMinimized() :
			self.prnt.showNormal()
		self.done(0)
Example #3
0
class Box(QTabWidget):
	mailAttr = pyqtSignal(dict)
	mailData = pyqtSignal(dict)
	def __init__(self, data = {}, parent = None):
		QTabWidget.__init__(self, parent)
		self.Parent = parent
		self.tr = Translator('mailViewer')
		self.mails = []
		self.webViewWDGs = []
		self.iconDatabasePath = os.path.join('/tmp', randomString(24))
		os.mkdir(self.iconDatabasePath)
		self.Settings = Settings

		self.setMovable(True)
		self.setIconSize(QSize(SIZE, SIZE))

		if 'ids' in data and len(data['ids']) :
			i = 0
			for idx in data['ids'] :
				self.mails.append(Mail(idx, self))

				self.addTab(self.mails[i], QIcon().fromTheme("mail"), QString(self.tr._translate('Mail') + ' ' + idx))
				self.setTabToolTip(i, self.tr._translate('Mail') + ' #' + idx)
				i += 1
			self.Parent.statusBar.showMessage(self.tr._translate('Getting mail...'))
			self.mailAttr.connect(self.setMailAttr)
			self.mailData.connect(self.setMailData)
			self.getMail = GetMail(data, self)
			self.startGetMail()
		else :
			self.Parent.statusBar.showMessage(self.tr._translate('Empty Job.'))

	def startGetMail(self):
		self.Parent.reload_.setEnabled(False)
		self.getMail.start()

	def setMailAttr(self, d):
		i = 0
		for m in self.mails :
			if m.idx == d['number'] : break
			else : i += 1
		self.mails[i].fromField.setText(d['from'])
		self.mails[i].subjField.setText(d['subj'])
		self.mails[i].dateField.setText(d['date'])
		self.mails[i].reply_to = d['ReplyTo']
		self.mails[i]._from_subj = d['_F_S']

	def setMailData(self, d):
		ll = d['data'][0]
		data = d['data'][1]
		i = 0
		for m in self.mails :
			if m.idx == d['number'] : break
			else : i += 1
		fileName = None
		if d['type'] == 'html' :
			_data = changeImagePath(data, d['boundary'])
			''' create temporary html-file '''
			fileName = os.path.join(self.iconDatabasePath, randomString(24) + '.html')
			with open(fileName, 'w') as f : f.write(insertMetaData(_data))
			wdg = QWebView()
			wdg.triggerPageAction(QWebPage.Reload, True)
			wdg.triggerPageAction(QWebPage.Stop, True)
			wdg.triggerPageAction(QWebPage.Back, True)
			wdg.triggerPageAction(QWebPage.Forward, True)
			wdg.settings().setAttribute(QWebSettings.AutoLoadImages, \
										self.Parent.autoLoadImage)
			wdg.settings().setAttribute(QWebSettings.PrivateBrowsingEnabled, \
										self.Parent.privateEnable)
			if wdg.settings().iconDatabasePath().isEmpty() :
				wdg.settings().setIconDatabasePath(self.iconDatabasePath)
			wdg.load(QUrl('file://' + fileName))
			#print dateStamp(), QUrl('file://' + fileName), '  created'
			wdg.show()
			self.webViewWDGs.append(wdg)
		elif d['type'] in ('plain') :
			wdg = QTextBrowser()
			wdg.setAcceptRichText(True)
			wdg.setOpenExternalLinks(True)
			wdg.setOpenLinks(True)
			data = data.replace('<', '&lt; ')
			data = data.replace('>', ' &gt;')
			wdg.setHtml(changeLink(data))
		elif d['type'] == 'header' :
			wdg = QLabel()
			wdg.setText(data)
			wdg.linkHovered.connect(self.linkDisplay)
			wdg.setAlignment(Qt.AlignLeft)
		else :
			''' create temporary file '''
			fileName = os.path.join(self.iconDatabasePath, d['data'][2])
			with open(fileName, 'wb') as f : f.write(data)
			wdg = QLabel()
			wdg.setOpenExternalLinks(True)
			ins = self.tr._translate('Inserted:')
			wdg.setText(QString('<a href="%1">%2 %3</a>').arg(fileName).arg(ins).arg(d['type']))
			wdg.linkHovered.connect(self.linkDisplay)
			wdg.setAlignment(Qt.AlignLeft)
		wdg.setToolTip(ll)
		splt = QSplitter()
		splt.setOrientation(Qt.Horizontal)
		splt.setChildrenCollapsible(True)
		if d['level'] :
			blank = QLabel()
			blank.setFixedWidth(d['level']*SIZE)
			splt.addWidget(blank)
		splt.addWidget(wdg)
		self.mails[i].mailField.addWidget(splt)
		self.mails[i].setLayout(self.mails[i].layout)

	def linkDisplay(self, s):
		self.Parent.statusBar.showMessage(s)

	def __del__(self):
		shutil.rmtree(self.iconDatabasePath)
Example #4
0
class AkonadiResources(QWidget):
	edit = pyqtSignal(QListWidgetItem)
	edited = pyqtSignal()
	reloadAkonadi = pyqtSignal()
	def __init__(self, obj = None, parent = None):
		QWidget.__init__(self)

		self.Parent = obj
		self.prnt = parent
		self.Settings = self.Parent.Settings
		self.checkAccess = self.Parent.checkAccess
		self.tr = Translator('EditAccounts')

		print dateStamp(), 'Module PyKDE4.akonadi is'
		if not A.AkonadiModuleExist :
			print '\tnot'
		print '\tavailable.'
		self.init()

	def init(self):
		self.layout = QGridLayout()
		self.VBLayout = QVBoxLayout()

		self.akonadiServer = QPushButton('&Restart')
		self.akonadiServer.setToolTip(self.tr._translate("Restart Akonadi Server"))
		self.akonadiServer.clicked.connect(self.reloadAkonadiStuff)
		self.layout.addWidget(self.akonadiServer, 0, 4)

		self.akonadiState = QLabel()
		if not A.AkonadiModuleExist :
			self.akonadiState.setText(self.tr._translate("Module PyKDE4.akonadi isn`t available."))
			akonadiAccList = []
		else :
			self.akonadiState.setText( self.tr._translate("Akonadi Server is : ") + \
										A.StateSTR[A.Akonadi.ServerManager.state()] )
			akonadiAccList = self.Parent.akonadiAccountList()
		self.layout.addWidget(self.akonadiState, 0, 0)

		self.VBLayout.addLayout(self.layout)

		self.editList = EditList(self.Parent, self)
		self.editParams = EditParam(self)

		self.VBLayout.addWidget(self.editList)
		self.VBLayout.addWidget(self.editParams)

		self.setLayout(self.VBLayout)

		self.edit.connect(self.editEvent)
		self.edited.connect(self.editedEvent)
		self.StateChanged = False
		self.setEditWidgetsState()

	def setEditWidgetsState(self):
		if A.AkonadiModuleExist and A.Akonadi.ServerManager.state() != A.Akonadi.ServerManager.State(4) :
			#self.editParams.changeSelfActivity(False)
			self.editList.changeSelfActivity(True)
		else :
			self.editList.changeSelfActivity(False)
		self.editParams.changeSelfActivity(False)

	def editEvent(self, item):
		self.StateChanged = True
		self.editList.changeSelfActivity(False)
		self.editParams.changeSelfActivity(True)
		self.editParams.initWidgets(item)

	def editedEvent(self):
		self.editParams.changeSelfActivity(False)
		self.editList.changeSelfActivity(True)
		self.StateChanged = False

	def collectionSearch(self):
		if not A.AkonadiModuleExist : return None
		self.Control = A.ControlWidget()
		if self.Control.exec_() :
			self.Control.move(self.Parent.popupPosition(self.Control.size()))
			col = self.Control.selectedCollection()
			## print dateStamp(), col.name().toUtf8(), col.id(), col.resource()
			self.editParams.collectionID.setText(str(col.id()))
			self.editParams.nameColl = col.name()
			#self.editList.stringEditor.setText(self.editParams.nameColl)
			self.editParams.collectionResource.setText(col.resource())

	def restartAkonadi(self):
		if not A.AkonadiModuleExist :
			self.akonadiState.setText(self.tr._translate("Module PyKDE4.akonadi isn`t available."))
			akonadiAccList = []
		else :
			server = A.Akonadi.Control()
			#server.widgetNeedsAkonadi(self)
			if A.Akonadi.ServerManager.isRunning() :
				if not server.restart(self) :
					print dateStamp(), 'Unable to start Akonadi Server '
			else :
				if not server.start(self) :
					print dateStamp(), 'Unable to start Akonadi Server '
			self.akonadiState.setText( self.tr._translate("Akonadi Server is : ") + \
											A.StateSTR[A.Akonadi.ServerManager.state()] )
		self.setEditWidgetsState()

	def reloadAkonadiStuff(self):
		self.reloadAkonadi.emit()

	def saveData(self):
		self.editParams.saveAccountData()

	def eventClose(self, event):
		self.prnt.done(0)
Example #5
0
class Box(QTabWidget):
	mailAttr = pyqtSignal(dict)
	mailData = pyqtSignal(dict)
	def __init__(self, data = {}, parent = None):
		QTabWidget.__init__(self, parent)
		self.Parent = parent
		self.tr = Translator('mailViewer')
		self.mails = []
		self.webViewWDGs = []
		self.iconDatabasePath = os.path.join('/tmp', randomString(24))
		os.mkdir(self.iconDatabasePath)
		self.Settings = Settings
		self.SoundEnabled = self.Settings.value('Sound', False).toBool()

		self.setMovable(True)
		self.setIconSize(QSize(SIZE, SIZE))

		if 'ids' in data and len(data['ids']) :
			i = 0
			for idx in data['ids'] :
				self.mails.append(Mail(idx, self))

				self.addTab(self.mails[i], QIcon().fromTheme("mail"), QString(self.tr._translate('Mail') + ' ' + idx))
				self.setTabToolTip(i, self.tr._translate('Mail') + ' #' + idx)
				i += 1
			self.Parent.statusBar.showMessage(self.tr._translate('Getting mail...'))
			self.mailAttr.connect(self.setMailAttr)
			self.mailData.connect(self.setMailData)
			self.getMail = GetMail(data, self)
			self.startGetMail()
		else :
			self.Parent.statusBar.showMessage(self.tr._translate('Empty Job.'))

	def startGetMail(self):
		self.Parent.reload_.setEnabled(False)
		self.getMail.start()

	def setMailAttr(self, d):
		i = 0
		for m in self.mails :
			if m.idx == d['number'] : break
			else : i += 1
		self.mails[i].fromField.setText(d['from'])
		self.mails[i].subjField.setText(d['subj'])
		self.mails[i].dateField.setText(d['date'])
		self.mails[i].reply_to = d['ReplyTo']
		self.mails[i]._from_subj = d['_F_S']

	def setMailData(self, d):
		ll = d['data'][0]
		data = d['data'][1]
		i = 0
		for m in self.mails :
			if m.idx == d['number'] : break
			else : i += 1
		fileName = None
		if d['type'] == 'html' :
			_data = changeImagePath(data, d['boundary'])
			''' create temporary html-file '''
			fileName = os.path.join(self.iconDatabasePath, randomString(24) + '.html')
			try :
				with open(fileName, 'w') as f :
					f.write(insertMetaData(_data))
			except Exception, err :
				print dateStamp(), err
				with open(fileName, 'w') as f :
					f.write(str(err))
			finally : pass 
			wdg = QWebView()
			wdg.triggerPageAction(QWebPage.Reload, True)
			wdg.triggerPageAction(QWebPage.Stop, True)
			wdg.triggerPageAction(QWebPage.Back, True)
			wdg.triggerPageAction(QWebPage.Forward, True)
			wdg.settings().setAttribute(QWebSettings.AutoLoadImages, \
										self.Parent.autoLoadImage)
			wdg.settings().setAttribute(QWebSettings.PrivateBrowsingEnabled, \
										self.Parent.privateEnable)
			if wdg.settings().iconDatabasePath().isEmpty() :
				wdg.settings().setIconDatabasePath(self.iconDatabasePath)
			wdg.load(QUrl('file://' + fileName))
			#print dateStamp(), QUrl('file://' + fileName), '  created'
			wdg.show()
			self.webViewWDGs.append(wdg)
		elif d['type'] in ('plain') :
			wdg = QTextBrowser()
			wdg.setAcceptRichText(True)
			wdg.setOpenExternalLinks(True)
			wdg.setOpenLinks(True)
			data = data.replace('<', '&lt; ')
			data = data.replace('>', ' &gt;')
			wdg.setHtml(changeLink(data))
Example #6
0
class MainWindow(QMainWindow):
    def __init__(self, parent=None):
        QMainWindow.__init__(self, parent)
        self.runned = False
        self.tr = Translator("Thrifty")

        # self.resize(450, 350)
        self.setWindowTitle(self.tr._translate("Thrifty"))
        self.setWindowIcon(QIcon("/usr/share/thrifty/icons/sniper_soldier.png"))

        self.Settings = QSettings("thrifty", "thrifty")

        self.exit_ = QAction(QIcon("/usr/share/thrifty/icons/exit.png"), self.tr._translate("&Exit"), self)
        self.exit_.setShortcut("Ctrl+Q")
        self.exit_.setStatusTip(self.tr._translate("Exit application"))
        self.connect(self.exit_, SIGNAL("triggered()"), self._close)

        listHelp = QAction(QIcon("/usr/share/thrifty/icons/help.png"), self.tr._translate("&About Thrifty"), self)
        listHelp.setStatusTip(self.tr._translate("Read help"))
        self.connect(listHelp, SIGNAL("triggered()"), self.showMSG)

        self.stopProcess = QAction(
            QIcon("/usr/share/thrifty/icons/terminate.png"), self.tr._translate("&Terminate Task"), self
        )
        self.stopProcess.setShortcut("Ctrl+T")
        self.stopProcess.setStatusTip(self.tr._translate("Terminate running task ..."))
        self.stopProcess.setEnabled(False)
        self.connect(self.stopProcess, SIGNAL("triggered()"), self.terminateRunningTask)

        self.separator = QAction("", self)
        self.separator.setSeparator(True)

        self.checkMode = QAction(self.tr._translate("check file`s &mode"), self)
        self.checkMode.setCheckable(True)
        value = str(self.Settings.value("checkFileMode", "False").toString())
        if value.lower() == "true":
            self.checkMode.setChecked(True)
        else:
            self.checkMode.setChecked(False)
        self.connect(self.checkMode, SIGNAL("changed()"), self.setCheckMode)

        self.checkOwners = QAction(self.tr._translate("check  file`s &owners"), self)
        self.checkOwners.setCheckable(True)
        value = str(self.Settings.value("checkFileOwners", "False").toString())
        if value.lower() == "true":
            self.checkOwners.setChecked(True)
        else:
            self.checkOwners.setChecked(False)
        self.connect(self.checkOwners, SIGNAL("changed()"), self.setCheckOwners)

        self.checkMtime = QAction(self.tr._translate("check  file`s mt&ime"), self)
        self.checkMtime.setCheckable(True)
        value = str(self.Settings.value("checkFileMtime", "False").toString())
        if value.lower() == "true":
            self.checkMtime.setChecked(True)
        else:
            self.checkMtime.setChecked(False)
        self.connect(self.checkMtime, SIGNAL("changed()"), self.setCheckMtime)

        self.statusBar = StatusBar(self)
        self.setStatusBar(self.statusBar)

        self.prelink = QAction(QIcon("/usr/share/thrifty/icons/prelink.png"), self.tr._translate("&Prelink"), self)
        self.prelink.setShortcut("Ctrl+P")
        self.prelink.setStatusTip(self.tr._translate("Prelink now"))
        self.prelink.setEnabled(prelinkInstalled)
        self.connect(self.prelink, SIGNAL("triggered()"), self.runPrelink)

        menubar = self.menuBar()

        file_ = menubar.addMenu(self.tr._translate("&File"))
        file_.addAction(self.prelink)
        file_.addAction(self.exit_)

        set_ = menubar.addMenu(self.tr._translate("&Control"))
        set_.addAction(self.stopProcess)
        set_.addAction(self.separator)
        set_.addAction(self.checkMode)
        set_.addAction(self.checkOwners)
        set_.addAction(self.checkMtime)

        help_ = menubar.addMenu(self.tr._translate("&Help"))
        help_.addAction(listHelp)

        self.menuTab = Box(self)
        self.setCentralWidget(self.menuTab)

    def setCheckMode(self):
        state = self.checkMode.isChecked()
        print state
        self.Settings.setValue("checkFileMode", state)

    def setCheckOwners(self):
        state = self.checkOwners.isChecked()
        # print state
        self.Settings.setValue("checkFileOwners", state)

    def setCheckMtime(self):
        state = self.checkMtime.isChecked()
        # print state
        self.Settings.setValue("checkFileMtime", state)

    def detectRunningTask(self):
        name = "Unknown"
        obj = None
        if self.menuTab.checkFile.runned:
            name = "CheckFile"
            obj = self.menuTab.checkFile
        elif self.menuTab.backUp.runned:
            name = "BackUp"
            obj = self.menuTab.backUp
        elif self.menuTab.cleanUp.runned:
            name = "CleanUp"
            obj = self.menuTab.cleanUp
        elif self.menuTab.broken.runned:
            name = "Search Broken"
            obj = self.menuTab.broken
        elif self.runned:
            name = "Prelink"
            obj = self
        return name, obj

    def terminateRunningTask(self):
        name, obj = self.detectRunningTask()
        # print 'Terminated Task : %s' % name
        if obj is not None:
            obj.t.terminate()

    def runPrelink(self):
        self.prelink.setEnabled(False)
        self.menuTab.setTabsState(False)
        # self.progress.show()
        self.runned = True
        print "Prelink running  ..."
        self.t = QProcess()
        Data = QStringList()
        Data.append("prelink")
        Data.append("-a")
        self.t.finished.connect(self.showResult)
        self.t.start("pkexec", Data)
        if self.t.waitForStarted():
            self.runned = True
            # print self.t.state()
        else:
            self.showResult()

    def showResult(self):
        self.prelink.setEnabled(True)
        self.runned = False
        self.menuTab.setTabsState(True)

    def showMSG(self, s=""):
        msg = ListingText(HELP if s == "" else s, self)
        msg.exec_()

    def _close(self):
        self.Settings.sync()
        self.close()
Example #7
0
class Font_n_Colour(QWidget):
	def __init__(self, obj = None, parent = None):
		QWidget.__init__(self)

		self.Parent = obj
		self.prnt = parent
		self.Settings = self.Parent.Settings
		self.checkAccess = self.Parent.checkAccess
		self.tr = Translator('Font_n_Colour')

		self.headerFontVar = self.initValue('headerFont', ' ')
		self.headerSizeVar = self.initValue('headerSize')
		self.headerBoldVar = self.initValue('headerBold')
		self.headerItalVar = self.initValue('headerItal')
		self.headerColourVar = self.initValue('headerColour')

		self.accountFontVar = self.initValue('accountFont', ' ')
		self.accountSizeVar = self.initValue('accountSize')
		self.accountBoldVar = self.initValue('accountBold')
		self.accountItalVar = self.initValue('accountItal')
		self.accountColourVar = self.initValue('accountColour')
		self.accountSFontVar = self.initValue('accountSFont', ' ')
		self.accountSSizeVar = self.initValue('accountSSize')
		self.accountSBoldVar = self.initValue('accountSBold')
		self.accountSItalVar = self.initValue('accountSItal')
		self.accountSColourVar = self.initValue('accountSColour')

		self.accountToolTipFontVar = self.initValue('accountToolTipFont', ' ')
		self.accountToolTipSizeVar = self.initValue('accountToolTipSize')
		self.accountToolTipBoldVar = self.initValue('accountToolTipBold')
		self.accountToolTipItalVar = self.initValue('accountToolTipItal')
		self.accountToolTipColourVar = self.initValue('accountToolTipColour')
		self.accountToolTipSFontVar = self.initValue('accountToolTipSFont', ' ')
		self.accountToolTipSSizeVar = self.initValue('accountToolTipSSize')
		self.accountToolTipSBoldVar = self.initValue('accountToolTipSBold')
		self.accountToolTipSItalVar = self.initValue('accountToolTipSItal')
		self.accountToolTipSColourVar = self.initValue('accountToolTipSColour')

		self.countFontVar = self.initValue('countFont', ' ')
		self.countSizeVar = self.initValue('countSize')
		self.countBoldVar = self.initValue('countBold')
		self.countItalVar = self.initValue('countItal')
		self.countColourVar = self.initValue('countColour')
		self.countSFontVar = self.initValue('countSFont', ' ')
		self.countSSizeVar = self.initValue('countSSize')
		self.countSBoldVar = self.initValue('countSBold')
		self.countSItalVar = self.initValue('countSItal')
		self.countSColourVar = self.initValue('countSColour')

		self.countToolTipFontVar = self.initValue('countToolTipFont', ' ')
		self.countToolTipSizeVar = self.initValue('countToolTipSize')
		self.countToolTipBoldVar = self.initValue('countToolTipBold')
		self.countToolTipItalVar = self.initValue('countToolTipItal')
		self.countToolTipColourVar = self.initValue('countToolTipColour')
		self.countToolTipSFontVar = self.initValue('countToolTipSFont', ' ')
		self.countToolTipSSizeVar = self.initValue('countToolTipSSize')
		self.countToolTipSBoldVar = self.initValue('countToolTipSBold')
		self.countToolTipSItalVar = self.initValue('countToolTipSItal')
		self.countToolTipSColourVar = self.initValue('countToolTipSColour')

		self.fieldBoxFontVar = self.initValue('fieldBoxFont', ' ')
		self.fieldBoxSizeVar = self.initValue('fieldBoxSize')
		self.fieldBoxBoldVar = self.initValue('fieldBoxBold')
		self.fieldBoxItalVar = self.initValue('fieldBoxItal')
		self.fieldBoxColourVar = self.initValue('fieldBoxColour')

		self.fieldFromFontVar = self.initValue('fieldFromFont', ' ')
		self.fieldFromSizeVar = self.initValue('fieldFromSize')
		self.fieldFromBoldVar = self.initValue('fieldFromBold')
		self.fieldFromItalVar = self.initValue('fieldFromItal')
		self.fieldFromColourVar = self.initValue('fieldFromColour')

		self.fieldSubjFontVar = self.initValue('fieldSubjFont', ' ')
		self.fieldSubjSizeVar = self.initValue('fieldSubjSize')
		self.fieldSubjBoldVar = self.initValue('fieldSubjBold')
		self.fieldSubjItalVar = self.initValue('fieldSubjItal')
		self.fieldSubjColourVar = self.initValue('fieldSubjColour')

		self.fieldDateFontVar = self.initValue('fieldDateFont', ' ')
		self.fieldDateSizeVar = self.initValue('fieldDateSize')
		self.fieldDateBoldVar = self.initValue('fieldDateBold')
		self.fieldDateItalVar = self.initValue('fieldDateItal')
		self.fieldDateColourVar = self.initValue('fieldDateColour')

		self.headerColourStyle = self.getRGBaStyle(QString(self.headerColourVar).toUInt())
		self.accountColourStyle = self.getRGBaStyle(QString(self.accountColourVar).toUInt())
		self.accountSColourStyle = self.getRGBaStyle(QString(self.accountSColourVar).toUInt())
		self.accountToolTipColourStyle = self.getRGBaStyle(QString(self.accountToolTipColourVar).toUInt())
		self.accountToolTipSColourStyle = self.getRGBaStyle(QString(self.accountToolTipSColourVar).toUInt())
		self.countColourStyle = self.getRGBaStyle(QString(self.countColourVar).toUInt())
		self.countSColourStyle = self.getRGBaStyle(QString(self.countSColourVar).toUInt())
		self.countToolTipColourStyle = self.getRGBaStyle(QString(self.countToolTipColourVar).toUInt())
		self.countToolTipSColourStyle = self.getRGBaStyle(QString(self.countToolTipSColourVar).toUInt())
		self.fieldBoxColourStyle = self.getRGBaStyle(QString(self.fieldBoxColourVar).toUInt())
		self.fieldFromColourStyle = self.getRGBaStyle(QString(self.fieldFromColourVar).toUInt())
		self.fieldSubjColourStyle = self.getRGBaStyle(QString(self.fieldSubjColourVar).toUInt())
		self.fieldDateColourStyle = self.getRGBaStyle(QString(self.fieldDateColourVar).toUInt())

		self.fontIcon = QIcon().fromTheme("preferences-desktop-font")
		self.colourIcon = QIcon().fromTheme("format-text-color")

		self.init()

	def init(self):
		self.layout = QGridLayout()

		self.label1 = QLabel(self.tr._translate("Normal"))
		self.label2 = QLabel(self.tr._translate("Select"))
		self.label1.setMaximumHeight(30)
		self.label2.setMaximumHeight(30)
		self.layout.addWidget(self.label1, 0, 0)
		self.layout.addWidget(self.label2, 0, 5)

		prefix, suffix = self.cursive_n_bold(self.headerBoldVar, self.headerItalVar)
		self.headerFontLabel = QLabel('<font face="' + self.headerFontVar + \
											'">' + prefix + self.tr._translate('Header :') + suffix + '</font>')
		self.headerFontLabel.setStyleSheet(self.headerColourStyle)
		self.layout.addWidget(self.headerFontLabel, 1, 0)

		self.headerFontButton = QPushButton(self.fontIcon, '')
		self.headerFontButton.setToolTip('Font')
		self.headerFontButton.clicked.connect(self.headerFont)
		self.layout.addWidget(self.headerFontButton, 1, 1)

		self.headerColourButton = QPushButton(self.colourIcon, '')
		self.headerColourButton.setToolTip('Color')
		self.connect(self.headerColourButton, SIGNAL('clicked()'), self.headerColour)
		self.layout.addWidget(self.headerColourButton, 1, 2)

		prefix, suffix = self.cursive_n_bold(self.accountBoldVar, self.accountItalVar)
		self.accountFontLabel = QLabel('<font face="' + \
						self.accountFontVar + '">' + prefix + self.tr._translate('Account :') + suffix + '</font>')
		self.accountFontLabel.setStyleSheet(self.accountColourStyle)
		self.layout.addWidget(self.accountFontLabel, 2, 0)
		prefix, suffix = self.cursive_n_bold(self.accountSBoldVar, self.accountSItalVar)
		self.accountSFontLabel = QLabel('<font face="' + self.accountSFontVar + \
												'">' + prefix + self.tr._translate('Account :') + suffix + '</font>')
		self.accountSFontLabel.setStyleSheet(self.accountSColourStyle)
		self.layout.addWidget(self.accountSFontLabel, 2, 5)

		self.accountFontButton = QPushButton(self.fontIcon, '')
		self.accountFontButton.setToolTip('Font')
		self.connect(self.accountFontButton, SIGNAL('clicked()'), self.accountFont)
		self.layout.addWidget(self.accountFontButton, 2, 1)

		self.accountColourButton = QPushButton(self.colourIcon, '')
		self.accountColourButton.setToolTip('Color')
		self.connect(self.accountColourButton, SIGNAL('clicked()'), self.accountColour)
		self.layout.addWidget(self.accountColourButton, 2, 2)

		self.accountSFontButton = QPushButton(self.fontIcon, '')
		self.accountSFontButton.setToolTip('Font')
		self.connect(self.accountSFontButton, SIGNAL('clicked()'), self.accountSFont)
		self.layout.addWidget(self.accountSFontButton, 2, 3)

		self.accountSColourButton = QPushButton(self.colourIcon, '')
		self.accountSColourButton.setToolTip('Color')
		self.connect(self.accountSColourButton, SIGNAL('clicked()'), self.accountSColour)
		self.layout.addWidget(self.accountSColourButton, 2, 4)

		prefix, suffix = self.cursive_n_bold(self.accountToolTipBoldVar, self.accountToolTipItalVar)
		self.accountToolTipFontLabel = QLabel('<font face="' + self.accountToolTipFontVar + '">' + \
											prefix + self.tr._translate('Account\nToolTip :') + suffix + '</font>')
		self.accountToolTipFontLabel.setStyleSheet(self.accountToolTipColourStyle)
		self.layout.addWidget(self.accountToolTipFontLabel, 3, 0)
		prefix, suffix = self.cursive_n_bold(self.accountToolTipSBoldVar, self.accountToolTipSItalVar)
		self.accountToolTipSFontLabel = QLabel('<font face="' + self.accountToolTipSFontVar + '">' + \
											prefix + self.tr._translate('Account\nToolTip :') + suffix + '</font>')
		self.accountToolTipSFontLabel.setStyleSheet(self.accountToolTipSColourStyle)
		self.layout.addWidget(self.accountToolTipSFontLabel, 3, 5)

		self.accountToolTipFontButton = QPushButton(self.fontIcon, '')
		self.accountToolTipFontButton.setToolTip('Font')
		self.connect(self.accountToolTipFontButton, SIGNAL('clicked()'), self.accountToolTipFont)
		self.layout.addWidget(self.accountToolTipFontButton, 3, 1)

		self.accountToolTipColourButton = QPushButton(self.colourIcon, '')
		self.accountToolTipColourButton.setToolTip('Color')
		self.connect(self.accountToolTipColourButton, SIGNAL('clicked()'), self.accountToolTipColour)
		self.layout.addWidget(self.accountToolTipColourButton, 3, 2)

		self.accountToolTipSFontButton = QPushButton(self.fontIcon, '')
		self.accountToolTipSFontButton.setToolTip('Font')
		self.connect(self.accountToolTipSFontButton, SIGNAL('clicked()'), self.accountToolTipSFont)
		self.layout.addWidget(self.accountToolTipSFontButton, 3, 3)

		self.accountToolTipSColourButton = QPushButton(self.colourIcon, '')
		self.accountToolTipSColourButton.setToolTip('Color')
		self.connect(self.accountToolTipSColourButton, SIGNAL('clicked()'), self.accountToolTipSColour)
		self.layout.addWidget(self.accountToolTipSColourButton, 3, 4)

		prefix, suffix = self.cursive_n_bold(self.countBoldVar, self.countItalVar)
		self.countFontLabel = QLabel('<font face="' + self.countFontVar + \
											'">' + prefix + self.tr._translate('count :') + suffix + '</font>')
		self.countFontLabel.setStyleSheet(self.countColourStyle)
		self.layout.addWidget(self.countFontLabel, 4, 0)
		prefix, suffix = self.cursive_n_bold(self.countSBoldVar, self.countSItalVar)
		self.countSFontLabel = QLabel('<font face="' + self.countSFontVar + \
											'">' + prefix + self.tr._translate('count :') + suffix + '</font>')
		self.countSFontLabel.setStyleSheet(self.countSColourStyle)
		self.layout.addWidget(self.countSFontLabel, 4, 5)

		self.countFontButton = QPushButton(self.fontIcon, '')
		self.countFontButton.setToolTip('Font')
		self.connect(self.countFontButton, SIGNAL('clicked()'), self.countFont)
		self.layout.addWidget(self.countFontButton, 4, 1)

		self.countColourButton = QPushButton(self.colourIcon, '')
		self.countColourButton.setToolTip('Color')
		self.connect(self.countColourButton, SIGNAL('clicked()'), self.countColour)
		self.layout.addWidget(self.countColourButton, 4, 2)

		self.countSFontButton = QPushButton(self.fontIcon, '')
		self.countSFontButton.setToolTip('Font')
		self.connect(self.countSFontButton, SIGNAL('clicked()'), self.countSFont)
		self.layout.addWidget(self.countSFontButton, 4, 3)

		self.countSColourButton = QPushButton(self.colourIcon, '')
		self.countSColourButton.setToolTip('Color')
		self.connect(self.countSColourButton, SIGNAL('clicked()'), self.countSColour)
		self.layout.addWidget(self.countSColourButton, 4, 4)

		prefix, suffix = self.cursive_n_bold(self.countToolTipBoldVar, self.countToolTipItalVar)
		self.countToolTipFontLabel = QLabel('<font face="' + self.countToolTipFontVar + '">' + \
											prefix + self.tr._translate('count\nToolTip :') + suffix + '</font>')
		self.countToolTipFontLabel.setStyleSheet(self.countToolTipColourStyle)
		self.layout.addWidget(self.countToolTipFontLabel, 5, 0)
		prefix, suffix = self.cursive_n_bold(self.countToolTipSBoldVar, self.countToolTipSItalVar)
		self.countToolTipSFontLabel = QLabel('<font face="' + self.countToolTipSFontVar + '">' + \
											prefix + self.tr._translate('count\nToolTip :') + suffix + '</font>')
		self.countToolTipSFontLabel.setStyleSheet(self.countToolTipSColourStyle)
		self.layout.addWidget(self.countToolTipSFontLabel, 5, 5)

		self.countToolTipFontButton = QPushButton(self.fontIcon, '')
		self.countToolTipFontButton.setToolTip('Font')
		self.connect(self.countToolTipFontButton, SIGNAL('clicked()'), self.countToolTipFont)
		self.layout.addWidget(self.countToolTipFontButton, 5, 1)

		self.countToolTipColourButton = QPushButton(self.colourIcon, '')
		self.countToolTipColourButton.setToolTip('Color')
		self.connect(self.countToolTipColourButton, SIGNAL('clicked()'), self.countToolTipColour)
		self.layout.addWidget(self.countToolTipColourButton, 5, 2)

		self.countToolTipSFontButton = QPushButton(self.fontIcon, '')
		self.countToolTipSFontButton.setToolTip('Font')
		self.connect(self.countToolTipSFontButton, SIGNAL('clicked()'), self.countToolTipSFont)
		self.layout.addWidget(self.countToolTipSFontButton, 5, 3)

		self.countToolTipSColourButton = QPushButton(self.colourIcon, '')
		self.countToolTipSColourButton.setToolTip('Color')
		self.connect(self.countToolTipSColourButton, SIGNAL('clicked()'), self.countToolTipSColour)
		self.layout.addWidget(self.countToolTipSColourButton, 5, 4)

		prefix, suffix = self.cursive_n_bold(self.fieldBoxBoldVar, self.fieldBoxItalVar)
		self.fieldBoxFontLabel = QLabel('<font face="' + self.fieldBoxFontVar + \
											'">' + prefix + self.tr._translate('field Box :') + suffix + '</font>')
		self.fieldBoxFontLabel.setStyleSheet(self.fieldBoxColourStyle)
		self.layout.addWidget(self.fieldBoxFontLabel, 6, 0)

		self.fieldBoxFontButton = QPushButton(self.fontIcon, '')
		self.fieldBoxFontButton.setToolTip('Font')
		self.fieldBoxFontButton.clicked.connect(self.fieldBoxFont)
		self.layout.addWidget(self.fieldBoxFontButton, 6, 1)

		self.fieldBoxColourButton = QPushButton(self.colourIcon, '')
		self.fieldBoxColourButton.setToolTip('Color')
		self.connect(self.fieldBoxColourButton, SIGNAL('clicked()'), self.fieldBoxColour)
		self.layout.addWidget(self.fieldBoxColourButton, 6, 2)

		prefix, suffix = self.cursive_n_bold(self.fieldFromBoldVar, self.fieldFromItalVar)
		self.fieldFromFontLabel = QLabel('<font face="' + self.fieldFromFontVar + \
											'">' + prefix + self.tr._translate('field From :') + suffix + '</font>')
		self.fieldFromFontLabel.setStyleSheet(self.fieldFromColourStyle)
		self.layout.addWidget(self.fieldFromFontLabel, 7, 0)

		self.fieldFromFontButton = QPushButton(self.fontIcon, '')
		self.fieldFromFontButton.setToolTip('Font')
		self.fieldFromFontButton.clicked.connect(self.fieldFromFont)
		self.layout.addWidget(self.fieldFromFontButton, 7, 1)

		self.fieldFromColourButton = QPushButton(self.colourIcon, '')
		self.fieldFromColourButton.setToolTip('Color')
		self.connect(self.fieldFromColourButton, SIGNAL('clicked()'), self.fieldFromColour)
		self.layout.addWidget(self.fieldFromColourButton, 7, 2)

		prefix, suffix = self.cursive_n_bold(self.fieldSubjBoldVar, self.fieldSubjItalVar)
		self.fieldSubjFontLabel = QLabel('<font face="' + self.fieldSubjFontVar + \
											'">' + prefix + self.tr._translate('field Subj :') + suffix + '</font>')
		self.fieldSubjFontLabel.setStyleSheet(self.fieldSubjColourStyle)
		self.layout.addWidget(self.fieldSubjFontLabel, 8, 0)

		self.fieldSubjFontButton = QPushButton(self.fontIcon, '')
		self.fieldSubjFontButton.setToolTip('Font')
		self.fieldSubjFontButton.clicked.connect(self.fieldSubjFont)
		self.layout.addWidget(self.fieldSubjFontButton, 8, 1)

		self.fieldSubjColourButton = QPushButton(self.colourIcon, '')
		self.fieldSubjColourButton.setToolTip('Color')
		self.connect(self.fieldSubjColourButton, SIGNAL('clicked()'), self.fieldSubjColour)
		self.layout.addWidget(self.fieldSubjColourButton, 8, 2)

		prefix, suffix = self.cursive_n_bold(self.fieldDateBoldVar, self.fieldDateItalVar)
		self.fieldDateFontLabel = QLabel('<font face="' + self.fieldDateFontVar + \
											'">' + prefix + self.tr._translate('field Date :') + suffix + '</font>')
		self.fieldDateFontLabel.setStyleSheet(self.fieldDateColourStyle)
		self.layout.addWidget(self.fieldDateFontLabel, 9, 0)

		self.fieldDateFontButton = QPushButton(self.fontIcon, '')
		self.fieldDateFontButton.setToolTip('Font')
		self.fieldDateFontButton.clicked.connect(self.fieldDateFont)
		self.layout.addWidget(self.fieldDateFontButton, 9, 1)

		self.fieldDateColourButton = QPushButton(self.colourIcon, '')
		self.fieldDateColourButton.setToolTip('Color')
		self.connect(self.fieldDateColourButton, SIGNAL('clicked()'), self.fieldDateColour)
		self.layout.addWidget(self.fieldDateColourButton, 9, 2)

		self.setLayout(self.layout)

	def initValue(self, key_, defaultValue = ''):
		if self.Settings.contains(key_) :
			#print dateStamp() ,  key_, self.Settings.value(key_).toString()
			return self.Settings.value(key_).toString()
		else :
			if defaultValue == '' :
				defaultValue = self.getSystemColor('int')
			self.Settings.setValue(key_, QVariant(defaultValue))
			#print dateStamp() ,  key_, self.Settings.value(key_).toString()
			return defaultValue

	def getSystemColor(self, key_ = ''):
		currentBrush = QPalette().windowText()
		colour = currentBrush.color()
		if key_ == 'int' :
			#print dateStamp() ,  colour.rgba()
			return str(colour.rgba())
		else :
			#print dateStamp() ,  str(colour.getRgb())
			return str(colour.getRgb())

	def cursive_n_bold(self, bold, italic):
		pref = ''
		suff = ''
		if bold == '1' :
			pref += '<b>'; suff += '</b>'
		if italic == '1' :
			pref = '<i>' + pref; suff += '</i>'
		return pref, suff

	def getFont(self, currentFont):
		selectFont, yes = QFontDialog.getFont(currentFont, self)
		str_ = string.split(selectFont.key(), ',')
		b = '0'; i = '0'
		if selectFont.bold() : b = '1'
		if selectFont.italic() : i = '1'
		return str_[0], str_[1], b, i, yes

	def getRGBaStyle(self, (colour, yes)):
		if yes :
			style = 'QLabel { color: rgba' + str(QColor().fromRgba(colour).getRgb()) + ';} '
		else :
			style = 'QLabel { color: rgba' + self.getSystemColor() + ';} '
		return style
Example #8
0
class Filters(QWidget):
	def __init__(self, obj = None, parent= None):
		QWidget.__init__(self, parent)

		self.Parent = obj
		self.prnt = parent
		self.tr = Translator('Filters')
		dir_ = os.path.expanduser('~/.config/plasmaMailChecker')

		self.filterFROM = os.path.join(dir_, 'filter.from')
		self.filterSUBJ = os.path.join(dir_, 'filter.subj')
		i = 0
		for path in (self.filterFROM, self.filterSUBJ) :
			if not os.path.isfile(path) :
				name = self.filterSUBJ if i else self.filterFROM
				with open(name, 'wb') as f : pass
				#print path, 'not exist'
			i += 1

		self.listFROM = dataToList(self.filterFROM)
		self.listSUBJ = dataToList(self.filterSUBJ)

		self.layout = QGridLayout()
		self.layout.setSpacing(0)

		self.labelFROM = QLabel(self.tr._translate("FROM field"))
		self.labelSUBJ = QLabel(self.tr._translate("SUBJ field"))
		self.layout.addWidget(self.labelFROM, 0, 1,  Qt.AlignHCenter)
		self.layout.addWidget(self.labelSUBJ, 0, 2,  Qt.AlignHCenter)

		self.fromEditor = QLineEdit()
		self.subjEditor = QLineEdit()
		self.fromListBox = QListWidget()
		self.fromListBox.setSortingEnabled(True)
		self.fromListBox.setToolTip(self.tr._translate("Filter`s strings"))
		self.fromListBox.addItems(self.listFROM)
		self.fromListBox.currentTextChanged.connect(self.from_FiltersChanged)
		self.subjListBox = QListWidget()
		self.subjListBox.setSortingEnabled(True)
		self.subjListBox.setToolTip(self.tr._translate("Filter`s strings"))
		self.subjListBox.addItems(self.listSUBJ)
		self.subjListBox.currentTextChanged.connect(self.subj_FiltersChanged)

		self.layout.addWidget(self.fromEditor, 1, 1)
		self.layout.addWidget(self.subjEditor, 1, 2)
		self.layout.addWidget(self.fromListBox, 2, 1)
		self.layout.addWidget(self.subjListBox, 2, 2)

		self.buttonFROM = ButtonPanel(0, self)
		self.buttonSUBJ = ButtonPanel(1, self)
		self.layout.addWidget(self.buttonFROM, 2, 0)
		self.layout.addWidget(self.buttonSUBJ, 2, 3)
		self.setLayout(self.layout)
		self.buttonFROM.setCurrentState()
		self.buttonSUBJ.setCurrentState()
		self.StateChanged = [False, False]

	def from_FiltersChanged(self):
		self.StateChanged[0] = True

	def subj_FiltersChanged(self):
		self.StateChanged[1] = True

	def addItem(self, id_):
		if id_ :
			text = self.subjEditor.text()
			if not text.isEmpty() :
				self.subjListBox.addItem(text)
				self.StateChanged[id_] = True
			self.subjEditor.clear()
		else :
			text = self.fromEditor.text()
			if not text.isEmpty() :
				self.fromListBox.addItem(text)
				self.StateChanged[id_] = True
			self.fromEditor.clear()

	def delItem(self, id_):
		if id_ :
			item_ = self.subjListBox.currentRow()
			self.subjListBox.takeItem(item_)
		else :
			item_ = self.fromListBox.currentRow()
			self.fromListBox.takeItem(item_)
		self.StateChanged[id_] = True

	def saveFilter(self, id_):
		if id_ :
			i = 0
			filter_ = []
			while i < self.subjListBox.count() :
				filter_.append(self.subjListBox.item(i).text().toUtf8().data())
				#print unicode(QString().fromUtf8(self.subjListBox.item(i).text()))
				i += 1
			saveListToFile(filter_, self.filterSUBJ)
			SUBJ_filter = dataToList(self.filterSUBJ)
		else :
			i = 0
			filter_ = []
			while i < self.fromListBox.count() :
				filter_.append(self.fromListBox.item(i).text().toUtf8().data())
				#print unicode(QString().fromUtf8(self.fromListBox.item(i).text()))
				i += 1
			saveListToFile(filter_, self.filterFROM)
			FROM_filter = dataToList(self.filterFROM)
		self.StateChanged[id_] = False

	def activateSide(self, id_, state = False):
		if id_ :
			self.buttonSUBJ.addButton.setEnabled(state)
			self.buttonSUBJ.delButton.setEnabled(state)
			self.buttonSUBJ.saveButton.setEnabled(state)
			self.subjEditor.setEnabled(state)
			self.subjListBox.setEnabled(state)
		else :
			self.buttonFROM.addButton.setEnabled(state)
			self.buttonFROM.delButton.setEnabled(state)
			self.buttonFROM.saveButton.setEnabled(state)
			self.fromEditor.setEnabled(state)
			self.fromListBox.setEnabled(state)
Example #9
0
class Editor(QMainWindow):
	def __init__(self, path = '', mode = 1, parent = None, task = None):
		QMainWindow.__init__(self, parent)
		self.tr = Translator('Thrifty')

		#self.resize(450, 350)
		self.setWindowTitle(self.tr._translate('Thrifty'))
		self.setWindowIcon(QIcon('/usr/share/thrifty/icons/sniper_soldier.png'))

		self.save_ = QAction(QIcon('/usr/share/thrifty/icons/save.png'), self.tr._translate('&Save'), self)
		self.save_.setShortcut('Ctrl+S')
		self.save_.setStatusTip(self.tr._translate('Save file'))
		self.connect(self.save_, SIGNAL('triggered()'), self._save)

		self.exit_ = QAction(QIcon('/usr/share/thrifty/icons/exit.png'), self.tr._translate('&Exit'), self)
		self.exit_.setShortcut('Ctrl+Q')
		self.exit_.setStatusTip(self.tr._translate('Exit application'))
		self.connect(self.exit_, SIGNAL('triggered()'), self._close)

		self.giveToYum = QAction(QIcon('/usr/share/thrifty/icons/exit.png'), self.tr._translate('to &Yum'), self)
		self.giveToYum.setShortcut('Ctrl+Y')
		self.giveToYum.setStatusTip(self.tr._translate('Give package list to Yum for reinstall'))
		self.connect(self.giveToYum, SIGNAL('triggered()'), self.runYum)
		self.giveToYum.setEnabled(False)

		menubar = self.menuBar()

		file_ = menubar.addMenu(self.tr._translate('&File'))
		file_.addAction(self.save_)
		file_.addAction(self.exit_)

		toYum = menubar.addMenu(self.tr._translate('&Action'))
		toYum.addAction(self.giveToYum)

		if task is not None :
			self.save_.setEnabled(False)
			if task : self.giveToYum.setEnabled(True)

		self.editor = QTextEdit(parent = self)
		self.setCentralWidget(self.editor)

		self.statusBar = StatusBar(self)
		self.setStatusBar(self.statusBar)

		self.Parent = parent
		self.mode = mode
		self.path = path
		self.editor.setUndoRedoEnabled(True)
		self.editor.setOverwriteMode(True)
		self.editor.createStandardContextMenu()
		if task is None :
			s = readFile(self.path)
		else : 
			s_ = readFile(self.path)
			if self.path == '' :
				s = s_
			else :
				l = []
				for item in s_.split('\n') :
					chunks = item.split(' ')
					if len(chunks) >= task + 1 :
						if chunks[task] != '' and chunks[task] not in l:
							l.append(chunks[task])
				_s = [s_ + '\n' for s_ in l]
				_s.sort()
				s = ''.join(_s)
		#print [s, QString().fromUtf8(s)]
		self.editor.setPlainText(QString().fromUtf8(s))
		self.statusBar.showMessage('Edit : ' + self.path)

	def runYum(self):
		self.save_.setEnabled(False)
		self.exit_.setEnabled(False)
		self.giveToYum.setEnabled(False)
		packageList = self.editor.toPlainText()
		self.editor.clear()
		self.editor.setReadOnly(True)
		Data = QStringList()
		Data.append('yum')
		Data.append('-y')
		Data.append('reinstall')
		for item in packageList.split('\n') :
			if item != '' :
				#print [item]
				Data.append(item)
		## run yum in dispatched process
		self.y = QProcess()
		self.y.readyReadStandardOutput.connect(self.appendOutputString)
		self.y.readyReadStandardError.connect(self.appendErrorString)
		self.y.finished.connect(self.showResult)
		self.y.start('pkexec', Data)
		if self.y.waitForStarted() :
			#print self.y.state()
			self.statusBar.showMessage(self.tr._translate('Yum runned...'))
		else :
			self.showResult()

	def appendOutputString(self):
		output = self.y.readAllStandardOutput()
		self.editor.append(QString().fromUtf8(output))

	def appendErrorString(self):
		error = self.y.readAllStandardError()
		self.editor.append(QString().fromUtf8(error))

	def showResult(self):
		self.exit_.setEnabled(True)
		self.statusBar.showMessage(self.tr._translate('Ready to exit.'))

	def _save(self):
		text = self.editor.toPlainText()
		if self.mode :
			with open(self.path, 'wb') as f :
				f.write(text.toUtf8().data())
		else :
			fileName = os.path.join('/tmp', randomString(12))
			with open(fileName, 'wb') as f :
				f.write(text.toUtf8().data())
			self.s = QProcess()
			Data = QStringList()
			Data.append('/usr/bin/python')
			Data.append('/usr/share/thrifty/saveHelper.py')
			Data.append(self.path)
			Data.append(fileName)
			self.s.finished.connect(self.showExitCode)
			#for i in xrange(Data.count()) :
			#	print Data[i],
			#print
			self.s.start('pkexec', Data)
			if self.s.waitForStarted() :
				print 'status %s' % self.s.state()
			else :
				print '%s not saved' % self.path
				self.showExitCode()

	def showExitCode(self):
		self.statusBar.showMessage(self.tr._translate('Exit code: ') + str(self.s.exitCode()))

	def _close(self):
		self.Parent.enableEditorButton()
		self.close()

	def closeEvent(self, e):
		self.Parent.enableEditorButton()
		e.accept()
Example #10
0
class Broken(QWidget):
	def __init__(self, parent = None):
		QWidget.__init__(self, parent)
		self.Parent = parent
		self.tr = Translator('Thrifty')
		self.runned = False
		self.pathToLog = None

		self.layout = QGridLayout()
		self.layout.setAlignment(Qt.AlignCenter)

		self.dirList = QListWidget()
		#self.dirList.setMaximumHeight(150)
		self.dirList.setToolTip(self.tr._translate('A list of directories processed'))

		self.buttonLayout = QVBoxLayout()
		self.buttonLayout.setAlignment(Qt.AlignCenter)
		self.addPath = QPushButton(QIcon('/usr/share/thrifty/icons/plus.png'), '')
		self.addPath.setIconSize(QSize(32,32))
		self.delPath = QPushButton(QIcon('/usr/share/thrifty/icons/delete.png'), '')
		self.delPath.setIconSize(QSize(32,32))
		self.showTargets = QPushButton(QIcon('/usr/share/thrifty/icons/show.png'), '')
		self.showTargets.setIconSize(QSize(32,32))
		self.mode = QComboBox()
		self.mode.setIconSize(QSize(32,32))
		self.mode.setToolTip(self.tr._translate('Packages'))
		self.mode.addItem (QIcon('/usr/share/thrifty/icons/packages.png'), '')
		self.mode.addItem (QIcon('/usr/share/thrifty/icons/files.png'), '')
		self.start = QPushButton(QIcon('/usr/share/thrifty/icons/start.png'), '')
		self.start.setIconSize(QSize(32,32))
		self.addPath.setToolTip(self.tr._translate('Add to List'))
		self.delPath.setToolTip(self.tr._translate('Delete from List'))
		self.showTargets.setToolTip(self.tr._translate('show Targets file'))
		self.start.setToolTip(self.tr._translate('Start task'))
		self.addPath.clicked.connect(self.addDirPath)
		self.delPath.clicked.connect(self.delDirPath)
		self.showTargets.clicked.connect(self.showTargetsList)
		self.start.clicked.connect(self.runSearchBroken)

		self.buttonLayout.addWidget(self.addPath)
		self.buttonLayout.addWidget(self.delPath)
		self.buttonLayout.addWidget(self.start)
		self.buttonLayout.addWidget(self.mode)
		self.buttonLayout.addWidget(self.showTargets)

		self.progress = QProgressBar()
		self.progress.setOrientation(Qt.Vertical)
		self.progress.hide()
		self.progress.setRange(0, 0)

		self.logIn = QLabel('')
		self.logIn.setToolTip(self.tr._translate('Log of processed task'))
		self.logIn.setOpenExternalLinks(True)

		self.layout.addWidget(self.dirList, 0, 0)
		self.layout.addItem(self.buttonLayout, 0, 1)
		self.layout.addWidget(self.progress, 0, 2)
		self.layout.addWidget(self.logIn, 1, 0)

		self.setLayout(self.layout)
		self.mode.currentIndexChanged.connect(self.changeModeContent)

	def addDirPath(self):
		_nameDir = QFileDialog.getExistingDirectory(self, self.tr._translate('Path_to_'), '~', QFileDialog.ShowDirsOnly)
		nameDir = _nameDir.toLocal8Bit().data()
		if os.path.isdir(nameDir) and \
				os.access(nameDir, os.R_OK) and os.access(nameDir, os.X_OK) :
			self.dirList.addItem(_nameDir)
		else :
			msg = QMessageBox.information(self, 'ERROR', self.tr._translate('error'), QMessageBox.Ok)

	def delDirPath(self):
		item = self.dirList.takeItem(self.dirList.currentRow())

	def changeModeContent(self, i = 0):
		if i :
			self.mode.setToolTip(self.tr._translate('Files'))
		else :
			self.mode.setToolTip(self.tr._translate('Packages'))

	def runSearchBroken(self):
		self.Parent.setTabsState(False)
		self.progress.show()
		self.runned = True
		self.pathToLog = None
		print 'Search broken running  ...'
		self.t = QProcess()
		Data = QStringList()
		Data.append('--user')
		Data.append('root')
		Data.append('/usr/share/thrifty/thrifty.py')
		mode = '-b'
		value = str(self.Parent.Parent.Settings.value('checkFileOwners', 'False').toString())
		if value.lower() == 'true' :
			mode += 'O'
		value = str(self.Parent.Parent.Settings.value('checkFileMode', 'False').toString())
		if value.lower() == 'true' :
			mode += 'M'
		value = str(self.Parent.Parent.Settings.value('checkFileMtime', 'False').toString())
		if value.lower() == 'true' :
			mode += 'T'
		opt = ''.join(('G:', str(USER_UID), '/', str(USER_GID), '::', mode))
		Data.append(opt)
		for i in xrange(self.dirList.count()) :
			item_ = self.dirList.item(i)
			Data.append(item_.text())
		#for i in xrange(Data.count()) :
		#	print Data[i],
		self.t.finished.connect(self.showResult)
		self.t.start('pkexec', Data)
		if self.t.waitForStarted() :
			self.runned = True
			#print self.t.state()
		else :
			self.showResult()

	def setState(self, state):
		self.dirList.setEnabled(state)
		self.addPath.setEnabled(state)
		self.delPath.setEnabled(state)
		self.mode.setEnabled(state)
		self.showTargets.setEnabled(state)
		self.start.setEnabled(state)

	def showResult(self):
		self.runned = False
		self.Parent.setTabsState(True)
		self.progress.hide()
		name_ = '/dev/shm/thrifty.lastTask'
		if os.path.isfile(name_) :
			with open(name_, 'rb') as f :
				pathToLog = f.read()
			os.remove(name_)
			self.pathToLog = pathToLog
		else :
			pathToLog = 'ERROR'
		self.logIn.setText('<a href="%s">Log in $TEMP<a>' % pathToLog + '</a>')

	def showTargetsList(self):
		self.Parent.setTabsState(False)
		path_ = '' if self.pathToLog is None else self.pathToLog
		task = 0 if self.mode.currentIndex() else 1
		self.editor = Editor(path_, 0, self, task)
		self.editor.show()

	def enableEditorButton(self):
		self.Parent.setTabsState(True)
Example #11
0
class Mail(QWidget):
	def __init__(self, idx = None, parent = None):
		QWidget.__init__(self, parent)
		self.idx = idx
		self.Parent = parent
		self.tr = Translator('mailViewer')
		self.reply_to = None
		self._from_subj = (None, None)
		self.fromField = QLabel(self.tr._translate('From:'))
		self.fromField.setOpenExternalLinks(True)
		self.fromField.linkHovered.connect(self.linkDisplay)
		self.subjField = QLabel(self.tr._translate('Subj:'))
		self.dateField = QLabel(self.tr._translate('Date:'))

		self.sendRe = QPushButton(QIcon.fromTheme('mail-reply-custom'), '')
		self.sendRe.setToolTip(self.tr._translate('Quick Answer'))
		self.sendRe.setFixedWidth(self.Parent.iconSize().width())
		self.sendRe.setMinimumHeight(self.Parent.iconSize().height())
		self.sendRe.setContentsMargins(0, 0, 0, 0)
		self.sendRe.clicked.connect(self.sendReMail)
		self.sendFw = QPushButton(QIcon.fromTheme('mail-forward'), '')
		self.sendFw.setToolTip(self.tr._translate('Quick Forward'))
		self.sendFw.setFixedWidth(self.Parent.iconSize().width())
		self.sendFw.setMinimumHeight(self.Parent.iconSize().height())
		self.sendFw.setContentsMargins(0, 0, 0, 0)
		self.sendFw.clicked.connect(self.sendFwMail)

		self.mailField = QSplitter()
		self.mailField.setChildrenCollapsible(True)
		self.mailField.setOrientation(Qt.Vertical)
		self.mailField.setStretchFactor(1, 1)
		self.mailField.setHandleWidth(5)

		self.panel = QHBoxLayout()
		self.mailInfo = QVBoxLayout()
		self.mailInfo.addWidget(self.fromField)
		self.mailInfo.addWidget(self.subjField)
		self.mailInfo.addWidget(self.dateField)
		self.buttons = QVBoxLayout()
		self.buttons.addWidget(self.sendRe)
		self.buttons.addWidget(self.sendFw)
		self.panel.addItem(self.mailInfo)
		self.panel.addItem(self.buttons)

		self.layout = QVBoxLayout()
		self.layout.addItem(self.panel)
		self.layout.addWidget(self.mailField)
		self.layout.setContentsMargins(0, 0, 0, 0)
		self.layout.setSpacing(0)
		self.setLayout(self.layout)

	def linkDisplay(self, s):
		self.Parent.Parent.statusBar.showMessage(s)

	def sendReMail(self):
		self.sendMail('Re: ')
	def sendFwMail(self):
		self.sendMail('Fw: ')
	def sendMail(self, prefix):
		splt = self.mailField.widget(0)
		wdg = splt.widget(splt.count() - 1)
		if hasattr(wdg, 'toPlainText') : text = wdg.toPlainText()
		elif hasattr(wdg, 'title') : text = wdg.title()
		else : text = QString('<UNKNOWN_ERROR>')
		to_ = self._from_subj[0] if self.reply_to is None else self.reply_to
		self.sender = MailSender(to_, prefix, self._from_subj[1], text, self)
		self.sender.exec_()

	def __del__(self): self.close()
Example #12
0
class MainWindow(QMainWindow):
	def __init__(self, data = {}, parent = None):
		QMainWindow.__init__(self, parent)
		self.runned = False
		self.tr = Translator('mailViewer')
		self.autoLoadImage = False
		self.privateEnable = False
		self.data = data

		self.setWindowTitle(self.tr._translate('Mail Viewer'))
		self.setWindowIcon(QIcon().fromTheme("mail"))

		self.reload_ = QAction(QIcon().fromTheme("view-refresh"), '&'+self.tr._translate('Reload Job'), self)
		self.reload_.setShortcut('Ctrl+R')
		self.connect(self.reload_, SIGNAL('triggered()'), self.reloadJob)
		
		self.exit_ = QAction(QIcon().fromTheme("application-exit"), '&'+self.tr._translate('Exit'), self)
		self.exit_.setShortcut('Ctrl+Q')
		self.connect(self.exit_, SIGNAL('triggered()'), self._close)

		self.image_ = QAction(self.tr._translate('Image AutoLoad'), self)
		self.image_.setShortcut('Ctrl+I')
		self.image_.setCheckable(True)
		self.image_.setChecked(self.autoLoadImage)
		#self.image_.setIcon(QIcon().fromTheme("arrow-down-double"))
		self.connect(self.image_, SIGNAL('triggered()'), self._image)

		self.priv_ = QAction(self.tr._translate('Private Browsing'), self)
		self.priv_.setShortcut('Ctrl+P')
		self.priv_.setCheckable(True)
		self.priv_.setChecked(self.privateEnable)
		#self.priv_.setIcon(QIcon().fromTheme("user-group-delete"))
		self.connect(self.priv_, SIGNAL('triggered()'), self._private)

		self.menubar = self.menuBar()

		file_ = self.menubar.addMenu('&'+self.tr._translate('File'))
		file_.addAction(self.reload_)
		file_.addAction(self.exit_)

		sett_ = self.menubar.addMenu('&'+self.tr._translate('Settings'))
		sett_.addAction(self.image_)
		sett_.addAction(self.priv_)

		self.statusBar = QStatusBar(self)
		self.setStatusBar(self.statusBar)

		self.menuTab = Box(self.data, self)
		self.setCentralWidget(self.menuTab)

	def _image(self): self.regimeChange('image', self.image_.isChecked())

	def _private(self): self.regimeChange('private', self.priv_.isChecked())

	def regimeChange(self, parameter, state):
		if parameter == 'image' :
			attr = QWebSettings.AutoLoadImages
		else :
			attr = QWebSettings.PrivateBrowsingEnabled
		for wdg in self.menuTab.webViewWDGs :
			wdg.settings().setAttribute(attr, state)
			wdg.reload()

	def reloadJob(self):
		self.menuTab = Box(self.data, self)
		self.setCentralWidget(self.menuTab)
		self.menuTab.startGetMail()

	def _close(self): self.eventClose()

	def closeEvent(self, ev):
		self.menuTab.__del__()

	def eventClose(self):
		self.close()
Example #13
0
class AppletSettings(QWidget):
	def __init__(self, obj = None, parent= None):
		QWidget.__init__(self, parent)

		self.Parent = obj
		self.prnt = parent
		self.tr = Translator('AppletSettings')
		self.Settings = self.Parent.Settings
		self.checkAccess = self.Parent.checkAccess

		timeOut = self.initValue('TimeOut', '600')
		AutoRun = self.initValue('AutoRun', '0')
		countProbe = self.initValue('CountProbe', '3')
		showError = self.initValue('ShowError', '1')
		waitThread = self.initValue('WaitThread', '120')
		stayDebLog = self.initValue('stayDebLog', '5')
		showVersion = self.initValue('ShowVersion', '1')
		timeOutGroup = self.initValue('TimeOutGroup', '3')
		maxShowedMail = self.initValue('MaxShowedMail', '1024')
		mailsInGroup = self.initValue('MailsInGroup', '5')

		self.layout = QGridLayout()

		self.timeOutLabel = QLabel(self.tr._translate("Timeout checking (sec.):"))
		self.layout.addWidget(self.timeOutLabel,0,0)
		self.timeOutBox = KIntSpinBox(10, 7200, 1, int(timeOut), self)
		self.timeOutBox.setMaximumWidth(75)
		self.layout.addWidget(self.timeOutBox, 0, 5)

		self.autoRunLabel = QLabel(self.tr._translate("Autorun mail checking :"))
		self.layout.addWidget(self.autoRunLabel,1,0)
		self.AutoRunBox = QCheckBox()
		if int(AutoRun) > 0 :
			self.AutoRunBox.setCheckState(Qt.Checked)
		self.layout.addWidget(self.AutoRunBox,1,5)

		self.countProbe = QLabel(self.tr._translate("Count of connect probe\nto mail server:"))
		self.layout.addWidget(self.countProbe,2,0)
		self.countProbeBox = KIntSpinBox(1, 10, 1, int(countProbe), self)
		self.layout.addWidget(self.countProbeBox, 2, 5)

		self.showError = QLabel(self.tr._translate("Show error messages :"))
		self.layout.addWidget(self.showError,3,0)
		self.showErrorBox = QCheckBox()
		if int(showError) > 0 :
			self.showErrorBox.setCheckState(Qt.Checked)
		self.layout.addWidget(self.showErrorBox,3,5)

		self.waitThreadLabel = QLabel(self.tr._translate("Autoexit of connect (sec.):"))
		self.layout.addWidget(self.waitThreadLabel,4,0)
		self.waitThreadBox = KIntSpinBox(3, 7200, 1, int(waitThread), self)
		self.layout.addWidget(self.waitThreadBox, 4, 5)

		self.stayDebLogLabel = QLabel(self.tr._translate("Stay Debug output Log :"))
		self.layout.addWidget(self.stayDebLogLabel,5,0)
		self.stayDebLogBox = KIntSpinBox(1, 50, 1, int(stayDebLog), self)
		self.stayDebLogBox.setMaximumWidth(75)
		self.layout.addWidget(self.stayDebLogBox, 5, 5)

		self.showVersion = QLabel(self.tr._translate("Show Version :"))
		self.layout.addWidget(self.showVersion,6,0)
		self.showVersionBox = QCheckBox()
		if int(showVersion) > 0 :
			self.showVersionBox.setCheckState(Qt.Checked)
		self.layout.addWidget(self.showVersionBox,6,5)

		self.timeOutGroupLabel = QLabel(self.tr._translate("Group Akonadi events timeout (sec.):"))
		self.timeOutGroupLabel.setEnabled(AkonadiModuleExist)
		self.layout.addWidget(self.timeOutGroupLabel, 7, 0)
		self.timeOutGroupBox = KIntSpinBox(1, 200, 1, int(timeOutGroup), self)
		self.timeOutGroupBox.setMaximumWidth(75)
		self.timeOutGroupBox.setEnabled(AkonadiModuleExist)
		self.layout.addWidget(self.timeOutGroupBox, 7, 5)

		self.maxMailLabel = QLabel(self.tr._translate("Max Count of Showed Mail :"))
		self.layout.addWidget(self.maxMailLabel, 8, 0)
		self.maxMailBox = KIntSpinBox(1, 1024, 1, int(maxShowedMail), self)
		self.maxMailBox.setMaximumWidth(75)
		self.maxMailBox.valueChanged[int].connect(self.showMailGroupping)
		self.layout.addWidget(self.maxMailBox, 8, 5)

		self.mailInGroupLabel = QLabel('\t' + self.tr._translate("Count of Mail in Group for account:"))
		self.mailInGroupLabel.setEnabled(False)
		self.layout.addWidget(self.mailInGroupLabel, 9, 0)
		self.mailInGroupBox = KIntSpinBox(1, 10, 1, int(mailsInGroup), self)
		self.mailInGroupBox.setMaximumWidth(75)
		self.mailInGroupBox.setEnabled(False)
		self.layout.addWidget(self.mailInGroupBox, 9, 5)

		self.setLayout(self.layout)
		self.maxMailBox.valueChanged.emit(int(maxShowedMail))

	def initValue(self, key_, default = '0'):
		if self.Settings.contains(key_) :
			#print dateStamp() ,  key_, self.Settings.value(key_).toString()
			return self.Settings.value(key_).toString()
		else :
			self.Settings.setValue(key_, QVariant(default))
			#print dateStamp() ,  key_, self.Settings.value(key_).toString()
			return default

	def stateChanged(self, state):
		self.mailInGroupLabel.setEnabled(state)
		self.mailInGroupBox.setEnabled(state)

	def showMailGroupping(self, i):
		if i > self.mailInGroupBox.value() :
			self.stateChanged(True)
		else :
			self.stateChanged(False)

	def refreshSettings(self):
		if not self.checkAccess() : return None
		self.Settings.setValue('TimeOut', str(self.timeOutBox.value()))
		self.Settings.setValue('CountProbe', str(self.countProbeBox.value()))
		self.Settings.setValue('WaitThread', str(self.waitThreadBox.value()))
		self.Settings.setValue('stayDebLog', str(self.stayDebLogBox.value()))
		self.Settings.setValue('TimeOutGroup', str(self.timeOutGroupBox.value()))
		self.Settings.setValue('MaxShowedMail', str(self.maxMailBox.value()))
		self.Settings.setValue('MailsInGroup', str(self.mailInGroupBox.value()))
		if self.AutoRunBox.isChecked() :
			self.Settings.setValue('AutoRun', '1')
		else:
			self.Settings.setValue('AutoRun', '0')
		if self.showErrorBox.isChecked() :
			self.Settings.setValue('ShowError', '1')
		else:
			self.Settings.setValue('ShowError', '0')
		if self.showVersionBox.isChecked() :
			self.Settings.setValue('ShowVersion', '1')
		else:
			self.Settings.setValue('ShowVersion', '0')

		self.Settings.sync()

	def eventClose(self, event):
		self.prnt.done(0)
Example #14
0
class CheckFile(QWidget):
    def __init__(self, parent=None):
        QWidget.__init__(self, parent)
        self.Parent = parent
        self.runned = False
        self.otherDataList = [""]
        self.tr = Translator("Thrifty")
        self.trChunk0 = self.tr._translate("<pre>WARNING: not unique data in rpmDB (")
        self.trChunk1 = self.tr._translate(" records)")

        self.layout = QGridLayout()

        self.pathLayout = QHBoxLayout()

        self.pathString = QLineEdit("")
        self.pathString.returnPressed.connect(self.checkFile)
        self.searchPath = QPushButton(QIcon("/usr/share/thrifty/icons/file.png"), "")
        self.searchPath.setIconSize(QSize(32, 32))
        self.searchPath.setToolTip(self.tr._translate("Path to file"))
        self.searchPath.clicked.connect(self.addPath)

        self.pathLayout.addWidget(self.pathString)
        self.pathLayout.addWidget(self.searchPath)

        self.layout.addItem(self.pathLayout, 0, 0, 2, 3)

        self.package = QLabel(self.tr._translate("Package :"))

        self.mode = QComboBox()
        self.mode.setIconSize(QSize(32, 32))
        self.mode.addItem(QIcon("/usr/share/thrifty/icons/user.png"), "")
        self.mode.addItem(QIcon("/usr/share/thrifty/icons/admin.png"), "")
        self.mode.setToolTip(self.tr._translate("User Mode"))
        self.start = QPushButton(QIcon("/usr/share/thrifty/icons/start.png"), "")
        self.start.setIconSize(QSize(32, 32))
        self.start.clicked.connect(self.checkFile)
        self.start.setToolTip(self.tr._translate("Start task"))

        self.packageCheckSumm = QLabel(self.tr._translate("Package CheckSumm :"))
        self.checkSumm = QLabel(self.tr._translate("Real CheckSumm :"))
        self.packageRes = QComboBox()
        self.packageRes.setSizeAdjustPolicy(QComboBox.AdjustToContents)
        self.packageCheckSummRes = QLabel("")
        self.checkSummRes = QLabel("")
        self.otherData = QLabel("")
        self.layout.addWidget(self.package, 3, 0)
        self.layout.addWidget(self.mode, 4, 0, Qt.AlignLeft)
        self.layout.addWidget(self.start, 4, 0, Qt.AlignRight)
        self.layout.addWidget(self.packageCheckSumm, 5, 0)
        self.layout.addWidget(self.checkSumm, 6, 0)
        self.layout.addWidget(self.packageRes, 3, 1)
        self.layout.addWidget(self.otherData, 4, 1)
        self.layout.addWidget(self.packageCheckSummRes, 5, 1)
        self.layout.addWidget(self.checkSummRes, 6, 1)

        self.setLayout(self.layout)
        self.mode.currentIndexChanged.connect(self.changeMode)
        self.packageRes.currentIndexChanged.connect(self.changePackageContent)
        self.setMinimumSize(32, 32)

    def changeMode(self, i=0):
        if i:
            self.mode.setToolTip(self.tr._translate("Root Mode"))
        else:
            self.mode.setToolTip(self.tr._translate("User Mode"))

    def changePackageContent(self, i=0):
        self.otherData.setText(wrapData(self.otherDataList[i], self.trChunk0, self.trChunk1))
        self.checkSummRes.setText(self.otherDataList[i][13])
        self.packageCheckSummRes.setText(self.otherDataList[i][14])

    def addPath(self):
        fileName = QFileDialog.getOpenFileName(self, self.tr._translate("Path_to_"), "~")
        name_ = fileName.toLocal8Bit().data()
        if os.path.lexists(name_):  # and \
            # 	not stat.S_ISLNK(os.lstat(name_).st_mode) and os.access(name_, os.R_OK) :
            self.pathString.setText(fileName)
            self.pathString.setFocus()
        else:
            msg = QMessageBox.information(self, "ERROR", self.tr._translate("error"), QMessageBox.Ok)

    def checkFile(self):
        self.Parent.setTabsState(False)
        self.runned = True
        self.packageRes.currentIndexChanged.disconnect(self.changePackageContent)
        self.packageRes.clear()
        self.packageCheckSummRes.setText("")
        self.checkSummRes.setText("")
        self.otherData.setText("")
        self.otherDataList = [["" for i in xrange(12)] + ["0", "", "", "", ""]]
        mode = 0 if self.mode.currentIndex() else 1
        path = self.pathString.text().toUtf8().data()
        if not os.access(path, os.R_OK) and mode == 1:
            with open("/dev/shm/thrifty.lastTask", "wb") as f:
                message = self.tr._translate("Permission denied or File not exist.")
                f.write("package:" + message.toUtf8() + "\nmulti:0")
            self.showResult()
            return
        self.t = QProcess()
        Data = QStringList()
        Data.append("/usr/share/thrifty/thrifty.py")
        opt = "".join(("G:", str(USER_UID), "/", str(USER_GID), "::", "-f"))
        Data.append(opt)
        Data.append(self.pathString.text())
        self.t.finished.connect(self.showResult)
        if mode:
            self.t.start("python", Data)
        else:
            self.t.start("pkexec", Data)
        if self.t.waitForStarted():
            self.runned = True
            # print self.t.state()
        else:
            self.showResult()

    def setState(self, state):
        self.pathString.setEnabled(state)
        self.mode.setEnabled(state)
        self.start.setEnabled(state)
        self.otherData.setEnabled(state)
        self.searchPath.setEnabled(state)
        self.package.setEnabled(state)
        self.packageRes.setEnabled(state)
        self.packageCheckSumm.setEnabled(state)
        self.checkSumm.setEnabled(state)
        self.checkSummRes.setEnabled(state)
        self.packageCheckSummRes.setEnabled(state)

    def showResult(self):
        self.runned = False
        self.Parent.setTabsState(True)
        name_ = "/dev/shm/thrifty.lastTask"
        if os.path.isfile(name_):
            with open(name_, "rb") as f:
                __data = f.read()
            os.remove(name_)
            # print __data
            chunks = __data.split("</package>\n")
            empty = chunks.count("")
            for i in xrange(empty):
                chunks.remove("")
            if len(chunks) < 1:
                self.packageRes.addItem(self.tr._translate("Not packaged"))
            else:
                self.otherDataList = []
                for _data in chunks:
                    data = _data.split("\n")
                    STR = ["" for i in xrange(12)] + ["0", "", "", "", ""]
                    for item in data:
                        _data = item.split(":")
                        if len(_data) > 1:
                            if _data[0] == "package":
                                self.packageRes.addItem(_data[1].decode("utf-8"))
                            elif _data[0] == "sizeR":
                                STR[0] = _data[1]
                            elif _data[0] == "sizeP":
                                STR[1] = _data[1]
                            elif _data[0] == "modeR":
                                STR[2] = _data[1]
                            elif _data[0] == "modeP":
                                STR[3] = _data[1]
                            elif _data[0] == "uidR":
                                STR[4] = _data[1]
                            elif _data[0] == "uidP":
                                STR[5] = _data[1]
                            elif _data[0] == "gidR":
                                STR[6] = _data[1]
                            elif _data[0] == "gidP":
                                STR[7] = _data[1]
                            elif _data[0] == "mtimeR":
                                STR[8] = _data[1]
                            elif _data[0] == "mtimeP":
                                STR[9] = _data[1]
                            elif _data[0] == "linkR":
                                STR[10] = _data[1]
                            elif _data[0] == "linkP":
                                STR[11] = _data[1]
                            elif _data[0] == "multi":
                                STR[12] = _data[1]
                            elif _data[0] == "hashR":
                                STR[13] = (
                                    self.tr._translate("not prelinked, but in cache") if _data[1] == "256" else _data[1]
                                )
                            elif _data[0] == "hashP":
                                STR[14] = _data[1]
                            elif _data[0] == "binModeR":
                                STR[15] = _data[1]
                            elif _data[0] == "binModeP":
                                STR[16] = _data[1]
                    self.otherDataList.append(STR)
        else:
            self.packageRes.addItem(self.tr._translate("Error : not successfull."))
        self.packageRes.currentIndexChanged.connect(self.changePackageContent)
        # print self.otherDataList
        self.packageRes.currentIndexChanged.emit(0)
Example #15
0
class BackUp(QWidget):
	def __init__(self, parent = None):
		QWidget.__init__(self, parent)
		self.Parent = parent
		self.tr = Translator('Thrifty')
		self.runned = False
		self.trChunk0 = self.tr._translate('backs up own $HOME only')
		self.trChunk1 = self.tr._translate('without Excludes path.')
		self.trChunk2 = self.tr._translate('backs up catalogs:')
		self.trChunk3 = self.tr._translate('all real $HOMEs in system')

		self.layout = QGridLayout()
		self.layout.setAlignment(Qt.AlignLeft)

		self.buttonLayout = QVBoxLayout()
		self.buttonLayout.setAlignment(Qt.AlignCenter)
		self.mode = QComboBox()
		self.mode.setIconSize(QSize(32,32))
		#self.mode.addItems(QStringList() << 'User' << 'Root')
		self.mode.addItem (QIcon('/usr/share/thrifty/icons/user.png'), '')
		self.mode.addItem (QIcon('/usr/share/thrifty/icons/admin.png'), '')
		self.mode.setToolTip(self.tr._translate('User Mode'))
		self.speed = QComboBox()
		self.speed.setIconSize(QSize(32,32))
		#self.speed.addItems(QStringList() << 'Slow' << 'Normal' << 'Fast' << 'Fast+')
		self.speed.addItem (QIcon('/usr/share/thrifty/icons/slow.png'), '')
		self.speed.addItem (QIcon('/usr/share/thrifty/icons/normal.png'), '')
		self.speed.addItem (QIcon('/usr/share/thrifty/icons/fast.png'), '')
		self.speed.addItem (QIcon('/usr/share/thrifty/icons/fast+.png'), '')
		self.speed.setToolTip(self.tr._translate('Slow'))
		self.editExcludes = QPushButton(QIcon('/usr/share/thrifty/icons/edit.png'), '')
		self.editExcludes.setIconSize(QSize(32,32))
		self.editExcludes.setToolTip(self.tr._translate('Edit Excludes file for current regime'))
		self.editExcludes.clicked.connect(self.editExcludesFile)
		self.start = QPushButton(QIcon('/usr/share/thrifty/icons/start.png'), '')
		self.start.setIconSize(QSize(32,32))
		self.start.clicked.connect(self.runBackUp)
		self.start.setToolTip(self.tr._translate('Start task'))

		self.buttonLayout.addWidget(self.mode)
		self.buttonLayout.addWidget(self.speed)
		self.buttonLayout.addWidget(self.editExcludes)
		self.buttonLayout.addWidget(self.start)

		self.descriptionTask = QLabel('')
		self.descriptionTask.setAlignment(Qt.AlignLeft)

		self.progress = QProgressBar()
		self.progress.setOrientation(Qt.Vertical)
		self.progress.hide()
		self.progress.setRange(0, 0)

		self.logIn = QLabel('')
		self.logIn.setToolTip(self.tr._translate('Log of processed task'))
		self.logIn.setOpenExternalLinks(True)

		self.layout.addItem(self.buttonLayout, 0, 0)
		self.layout.addWidget(self.progress, 0, 1)
		self.layout.addWidget(self.descriptionTask, 0, 2)
		self.layout.addWidget(self.logIn, 1, 0)

		self.setLayout(self.layout)
		self.mode.currentIndexChanged.connect(self.changeModeContent)
		self.speed.currentIndexChanged.connect(self.changeSpeedContent)
		self.mode.currentIndexChanged.emit(0)

	def changeModeContent(self, i = 0):
		if i :
			self.mode.setToolTip(self.tr._translate('Root Mode'))
			self.descriptionTask.setText(ROOT_DESCRIPTION(self.trChunk2, self.trChunk3, self.trChunk1))
			self.editExcludes.setToolTip(self.tr._translate('Edit Excludes file for ') + \
					'<font color=red><b>ROOT</b></font> ' + \
					self.tr._translate('mode'))
		else :
			self.mode.setToolTip(self.tr._translate('User Mode'))
			self.descriptionTask.setText(USER_DESCRIPTION(self.trChunk0, self.trChunk1))
			self.editExcludes.setToolTip(self.tr._translate('Edit Excludes file for ') + \
					'<font color=green><b>USER</b></font> ' + \
					self.tr._translate('mode'))

	def changeSpeedContent(self, i = 0):
		if i == 3 :
			self.speed.setToolTip(self.tr._translate('Fast+'))
		elif i == 2 :
			self.speed.setToolTip(self.tr._translate('Fast'))
		elif i == 1 :
			self.speed.setToolTip(self.tr._translate('Normal'))
		else :
			self.speed.setToolTip(self.tr._translate('Slow'))

	def runBackUp(self):
		self.Parent.setTabsState(False)
		self.progress.show()
		self.runned = True
		mode = 0 if self.mode.currentIndex() else 1
		speed = SPEED[self.speed.currentIndex()]
		print 'BackUp running in %i mode and %i speed ...' % (mode, speed)
		self.t = QProcess()
		Data = QStringList()
		Data.append('/usr/share/thrifty/thrifty.py')
		opt = ''.join(('G:', str(USER_UID), '/', str(USER_GID), '::', str(speed)))
		Data.append(opt)
		self.t.finished.connect(self.showResult)
		if mode : self.t.start('python', Data)
		else : self.t.start('pkexec', Data)
		if self.t.waitForStarted() :
			self.runned = True
			#print self.t.state()
		else :
			self.showResult()

	def setState(self, state):
		self.mode.setEnabled(state)
		self.speed.setEnabled(state)
		self.editExcludes.setEnabled(state)
		self.start.setEnabled(state)
		self.descriptionTask.setEnabled(state)

	def showResult(self):
		self.runned = False
		self.Parent.setTabsState(True)
		self.progress.hide()
		name_ = '/dev/shm/thrifty.lastTask'
		if os.path.isfile(name_) :
			with open(name_, 'rb') as f :
				pathToLog = f.read()
			os.remove(name_)
		else :
			pathToLog = 'ERROR'
		self.logIn.setText('<a href="%s">Log in $TEMP<a>' % pathToLog)

	def editExcludesFile(self):
		self.Parent.setTabsState(False)
		mode = 0 if self.mode.currentIndex() else 1
		if mode :
			path_ = os.path.expanduser('~/.config/thrifty/thrifty.excludes')
		else :
			path_ = '/etc/thrifty.excludes'
		self.editor = Editor(path_, mode, self)
		self.editor.show()

	def enableEditorButton(self):
		self.Parent.setTabsState(True)
Example #16
0
class ProxySettings(QWidget):
	def __init__(self, obj = None, parent= None):
		QWidget.__init__(self, parent)

		self.Parent = obj
		self.prnt = parent
		self.tr = Translator('Proxy')
		self.Settings = obj.Settings
		self.loadSocksModule = obj.someFunctions.loadSocksModule

		self.layout = QGridLayout()
		self.layout.setSpacing(0)

		self.enableProxy = QCheckBox()
		self.enableProxy.setToolTip(self.tr._translate("Enable\Disable the Proxy"))
		self.Enabled = True if self.Settings.value('UseProxy', 'False')=='True' else False
		if self.Enabled : self.enableProxy.setCheckState(Qt.Checked)
		else : self.enableProxy.setCheckState(Qt.Unchecked)
		self.enableProxy.stateChanged.connect(self.activateProxy)
		self.layout.addWidget(self.enableProxy, 0, 0, Qt.AlignLeft)

		self.saveButton = QPushButton('&Save')
		#self.saveButton.setMaximumWidth(40)
		self.saveButton.clicked.connect(self.saveData)
		self.saveButton.setToolTip(self.tr._translate("Save"))

		self.layout.addWidget(self.saveButton, 0, 1,  Qt.AlignLeft)

		self.proxyTypeBox = QComboBox()
		#self.proxyTypeBox.addItem('HTTP', QVariant('HTTP'))
		self.proxyTypeBox.addItem('SOCKS4', QVariant('SOCKS4'))
		self.proxyTypeBox.addItem('SOCKS5', QVariant('SOCKS5'))
		self.proxyTypeBox.setToolTip(self.tr._translate("Proxy type"))
		data = self.Settings.value('ProxyType', 'SOCKS5')
		self.proxyTypeBox.setCurrentIndex(self.proxyTypeBox.findData(data))
		self.proxyTypeBox.currentIndexChanged.connect(self.stateChangedEvent)
		self.layout.addWidget(self.proxyTypeBox, 1, 0)

		self.Hlayout = QHBoxLayout()
		self.addrEditor = QLineEdit()
		self.addrEditor.setText(self.Settings.value('ProxyAddr', '').toString())
		self.addrEditor.setToolTip(self.tr._translate("Proxy address"))
		self.addrEditor.textChanged.connect(self.stateChangedEvent)
		self.Hlayout.addWidget(self.addrEditor, 0)

		self.portBox = QSpinBox()
		self.portBox.setMinimum(0)
		self.portBox.setMaximum(65535)
		value = self.Settings.value('ProxyPort', '3128' )
		self.portBox.setValue(int(str(value.toString())))
		self.portBox.setSingleStep(1)
		self.portBox.setToolTip(self.tr._translate('Proxy Port'))
		self.portBox.valueChanged.connect(self.stateChangedEvent)
		self.Hlayout.addWidget(self.portBox, 0,  Qt.AlignRight)

		self.layout.addItem(self.Hlayout, 1, 1)

		self.userLabel = QLabel(self.tr._translate("UserName :"******"Password :"******"Timeout Socks"))
		a, b, c = "If error: ['The read operation timed out']", \
				"in IMAP/IDLE connect is often,", \
				"then you should increase the timeout"
		description = QString('%1\n%2\n%3').arg(a).arg(b).arg(c)
		self.timeoutLabel.setToolTip(self.tr._translate(description))
		self.layout.addWidget(self.timeoutLabel, 4, 0)
		self.layout.addWidget(self.passwEditor, 3, 1)
		self.timeoutBox = QSpinBox()
		self.timeoutBox.setMinimum(30)
		self.timeoutBox.setMaximum(300)
		value = self.Settings.value('timeoutSocks', 45).toUInt()[0]
		self.timeoutBox.setValue(value)
		self.timeoutBox.setSingleStep(1)
		self.timeoutBox.setToolTip(self.tr._translate('Proxy TimeOut'))
		self.timeoutBox.valueChanged.connect(self.stateChangedEvent)
		self.layout.addWidget(self.timeoutBox, 4, 1, Qt.AlignRight)

		if self.loadSocksModule() : available = self.tr._translate("SocksiPy module loaded")
		else : available = self.tr._translate("SocksiPy module not loaded")
		self.proxyModuleLabel = QLabel(available)
		self.layout.addWidget(self.proxyModuleLabel, 0, 1, Qt.AlignRight)

		self.setLayout(self.layout)
		self.StateChanged = False
		self.activateProxy()

	def stateChangedEvent(self):
		self.StateChanged = True

	def saveData(self):
		self.Settings.setValue('ProxyType', self.proxyTypeBox.currentText())
		self.Settings.setValue('ProxyAddr', self.addrEditor.text())
		self.Settings.setValue('ProxyPort', self.portBox.value())
		self.Settings.setValue('ProxyUSER', self.userEditor.text())
		self.Settings.setValue('ProxyPASS', self.passwEditor.text())
		self.Settings.setValue('timeoutSocks', self.timeoutBox.value())
		self.StateChanged = False

	def activateProxy(self):
		state = True if self.enableProxy.checkState()==Qt.Checked else False
		if state : PROXY_Module = self.loadSocksModule(True)
		else : PROXY_Module = self.loadSocksModule(False)
		if PROXY_Module : available = self.tr._translate("SocksiPy module loaded")
		else : available = self.tr._translate("SocksiPy module not loaded")
		self.proxyModuleLabel.setText(available)
		if PROXY_Module and state : self.enableWidgets(True)
		else : self.enableWidgets(False)

	def enableWidgets(self, state):
		self.saveButton.setEnabled(state)
		self.addrEditor.setEnabled(state)
		self.portBox.setEnabled(state)
		self.userLabel.setEnabled(state)
		self.passwLabel.setEnabled(state)
		self.userEditor.setEnabled(state)
		self.passwEditor.setEnabled(state)
		self.proxyTypeBox.setEnabled(state)
		self.timeoutBox.setEnabled(state)
		self.timeoutLabel.setEnabled(state)
		self.layout.setEnabled(state)