Ejemplo n.º 1
0
	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.'))
Ejemplo n.º 2
0
	def add_service(self):
		if self.group is None :
			self.group = dbus.Interface(
					self.bus.get_object( avahi.DBUS_NAME, self.server.EntryGroupNew()),
					avahi.DBUS_INTERFACE_ENTRY_GROUP)
			self.group.connect_to_signal('StateChanged', self.entry_group_state_changed)

		print "Adding service '%s' of type '%s' ..." % (QtCore.QString(self.serviceName).toUtf8(), self.serviceType)

		try :
			str_ = ''
			for i in xrange(len(self.serviceTXT)) :
				str_ += self.serviceTXT[len(self.serviceTXT) - 1 - i]
			self.group.AddService(
				avahi.IF_UNSPEC,	#interface
				avahi.PROTO_UNSPEC, #protocol
				dbus.UInt32(0),				  #flags
				self.serviceName, self.serviceType,
				self.domain, self.host,
				dbus.UInt16(self.servicePort),
				avahi.string_array_to_txt_array(str_))
			self.group.Commit()
		except dbus.exceptions.DBusException, err :
			""" DBusError :  org.freedesktop.Avahi.CollisionError: Local name collision """
			#print 'DBusError : ', err
			self.serviceName += '_' + randomString(3)
			self.add_service()
Ejemplo n.º 3
0
	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()
Ejemplo n.º 4
0
	def commandBuild(self):
		if isinstance(self.param.keys()[0], int) :
			__str = ''
		else :
			__str = self.param.keys()[0]
		if self.command.count('integrated mail Viewer') :
			""" prepeare file with parameters """
			accName =  '' if __str is None else __str
			accIds = self.param[__str] if __str in self.param else ''
			self.Settings.beginGroup(accName)
			serv_ = self.Settings.value('server', '').toString().toLocal8Bit().data()
			port_ = self.Settings.value('port', '0').toString().toLocal8Bit().data()
			login_ = self.Settings.value('login', '').toString().toLocal8Bit().data()
			authMethod_ = self.Settings.value('authentificationMethod', '').toString().toLocal8Bit().data()
			connMethod_ = self.Settings.value('connectMethod', '').toString().toLocal8Bit().data()
			if str(connMethod_) == 'imap' :
				inbox = self.Settings.value('Inbox', '').toString().toLocal8Bit().data()
			else :
				inbox = ''
			anotherAuthData = False
			if self.Settings.value('anotherAuthData', '0').toString() == '1' :
				anotherAuthData = True
			self.Settings.endGroup()
			self.parent.wallet.setFolder(self.parent.appletName)
			accPswd = self.parent.wallet.readPassword(accName)[1]
			sendPass = ''
			if anotherAuthData and self.parent.wallet.hasFolder(self.parent.appletName+'_SEND') :
				self.parent.wallet.setFolder(self.parent.appletName+'_SEND')
				sendPass = self.parent.wallet.readPassword(accName)[1]
			if not isinstance(accPswd, basestring) :
				accPswd = accPswd.toLocal8Bit().data()
			if not isinstance(sendPass, basestring) :
				sendPass = sendPass.toLocal8Bit().data()
			## accName decode after accPswd for getting correct account password
			if not isinstance(accName, basestring) :
				accName = accName.toLocal8Bit().data()
			#print (anotherAuthData, accName, accPswd, sendPass)
			pathToViewer = self.parent.user_or_sys('contents/code/mailViewer.py')
			#print dateStamp() , (accName, serv_, port_, login_, authMethod_, \
			#					connMethod_, inbox, accPswd, accIds)
			str_ = str(randomString(24))
			with open('/dev/shm/' + str_, 'wb') as f:
				f.write(string.join((accName, serv_, port_, login_, authMethod_, \
								connMethod_, inbox, accPswd, sendPass), dlm))
			''' prepare command for integrated viewer '''
			self.COMMAND = string.join(('/usr/bin/python', pathToViewer, str_, accIds), ' ')
			#print accName, accIds, command, self.COMMAND
		else :
			''' prepare command '''
			if not isinstance(__str, basestring) :
				collId = __str.toLocal8Bit().data()
			else :
				collId = __str
			itemId = self.param[__str] if __str in self.param else ''
			_command = self.command.replace('%dir_id', collId).replace('%mail_id', itemId)
			self.COMMAND = '' if _command == '' else '/bin/bash -c "%s"' % _command
Ejemplo n.º 5
0
	def run(self):
		try:
			x = ''
			self.Timer.start(self.timeout)
			path = self.user_or_sys('code/mail.py')
			i = 0
			for accountData in self.accData :
				if self.WAIT :
					str_ = str(randomString(24))
					with open('/dev/shm/' + str_, 'wb') as f :
						if isinstance(accountData[1], basestring) :
							_str = accountData[1]
						else :
							_str = accountData[1].toLocal8Bit().data()
						f.write(_str)
					Data = QStringList()
					Data.append(path)
					Data.append(accountData[0])
					Data.append(str_)
					self.accountThread.append('')
					self.accountThread[i] = QProcess()
					start, pid = self.accountThread[i].startDetached('/usr/bin/python', Data, os.getcwd())
					self.dataList.append((pid, str_, start))
					#print dateStamp() ,  start, pid, Data.join(' ').toUtf8().data()
				else :
					break
				i += 1

			# waiting mailcheckig processes
			key_ = True
			while key_ and self.WAIT :
				self.msleep(100)
				key_ = False
				for node in self.dataList :
					if bool(node[2]) and node[0] != 0 :
						key_ = key_ or pid_exists(node[0], 0)
						#print node[2], node[0], ' ????', key_

		except Exception, x :
			self.Timer.stop()
			print dateStamp() ,  x, '  thread'
Ejemplo n.º 6
0
	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)