Beispiel #1
0
	def createMMS(self):
		slide = message.MMSMessagePage()
		if self.attachment != None:
			try:
				filetype = gnomevfs.get_mime_type(self.attachment)
			except:
				filetype = "unknown"
			if filetype.startswith("audio"):
				slide.addAudio(self.attachment)
			elif filetype.startswith("video"):
				slide.addVideo(self.attachment)
			else:
				slide.addImage(self.attachment)
		slide.addText(self.message)

		self._mms = message.MMSMessage()
		self._mms.headers['Subject'] = self.subject
		if "@" in self.number:
			self._mms.headers['To'] = str(self.number)
		elif ";" in self.number:
			fullnr = "";
			nr = self.number.split(";")
			for val in nr:
				fullnr = "%s%s" % (fullnr, (val.strip() + '/TYPE=PLMN;'))
			self._mms.headers['To'] = str(fullnr).rstrip(";")
		else:
			self._mms.headers['To'] = str(self.number) + '/TYPE=PLMN'
		if self._sender == '0':
			self._mms.headers['From'] = ''
		else:
			self._mms.headers['From'] = str(self._sender) + '/TYPE=PLMN'
		
		self._mms.addPage(slide)
Beispiel #2
0
    def send_mms(self, widget):
        """ sends the message (no shit?) """
        hildon.hildon_gtk_window_set_progress_indicator(self.window, 1)
        self.force_ui_update()

        to = self.eNumber.get_text()
        if not self.cont.validate_phonenumber_email(to) or to == "":
            self.show_system_note(
                gettext.ldgettext('rtcom-messaging-ui',
                                  "messaging_fi_smsc_invalid_chars"))
            return

        attachment = self.attachmentFile

        hildon.hildon_banner_show_information(self.window, "", \
             gettext.ldgettext('modest', "mcen_li_outbox_sending"))
        self.force_ui_update()

        if attachment == "" or attachment == None:
            attachment = None
            self.attachmentIsResized = False
        else:
            filetype = gnomevfs.get_mime_type(attachment)
            self.attachmentIsResized = False
            if self.config.get_img_resize_width() != 0 and filetype.startswith(
                    "image"):
                try:
                    attachment = self.resize_img(attachment)
                except Exception, e:
                    log.exception("resize failed: %s %s", type(e), e)
                    errmsg = str(e.args)
                    errstr = gettext.ldgettext('hildon-common-strings',
                                               "sfil_ni_operation_failed")
                    self.show_system_note("%s\n%s" % (errstr, errmsg))
                    raise
Beispiel #3
0
    def set_thumbnail(self, filename):
        try:
            filetype = gnomevfs.get_mime_type(filename)
        except:
            filetype = "unknown"
        if filetype.startswith("image") or filetype.startswith("sketch"):
            im = Image.open(filename)
            im.thumbnail((256, 256), Image.NEAREST)
            pixbuf = self.cont.image2pixbuf(im)
            image = gtk.Image()
            image.set_from_pixbuf(pixbuf)
        elif filetype.startswith("audio"):
            icon_theme = gtk.icon_theme_get_default()
            pixbuf = icon_theme.load_icon("mediaplayer_default_album", 128, 0)
            image = gtk.Image()
            image.set_from_pixbuf(pixbuf)
        elif filetype.startswith("video"):
            icon_theme = gtk.icon_theme_get_default()
            pixbuf = icon_theme.load_icon("general_video", 128, 0)
            image = gtk.Image()
            image.set_from_pixbuf(pixbuf)
        else:
            icon_theme = gtk.icon_theme_get_default()
            pixbuf = icon_theme.load_icon("tasklaunch_file_manager", 128, 0)
            image = gtk.Image()
            image.set_from_pixbuf(pixbuf)

        self.imageBox.remove(self.imageBoxContent)
        self.imageBoxContent = image
        self.imageBox.add(self.imageBoxContent)
        self.imageBox.show_all()
        return
Beispiel #4
0
	def send_mms(self, widget):
		""" sends the message (no shit?) """
		hildon.hildon_gtk_window_set_progress_indicator(self.window, 1)
		self.force_ui_update()
		
		to = self.eNumber.get_text()
		if not self.cont.validate_phonenumber_email(to) or to == "":
			self.show_system_note(gettext.ldgettext('rtcom-messaging-ui', "messaging_fi_smsc_invalid_chars"))
			return
		
		attachment = self.attachmentFile
		
		hildon.hildon_banner_show_information(self.window, "", \
							gettext.ldgettext('modest', "mcen_li_outbox_sending"))
		self.force_ui_update()
		
		if attachment == "" or attachment == None:
			attachment = None
			self.attachmentIsResized = False
		else:
			filetype = gnomevfs.get_mime_type(attachment)
			self.attachmentIsResized = False
			if self.config.get_img_resize_width() != 0 and filetype.startswith("image"):
				try:
					attachment = self.resize_img(attachment)
				except Exception, e:
					log.exception("resize failed: %s %s", type(e), e)
					errmsg = str(e.args)
					errstr = gettext.ldgettext('hildon-common-strings', "sfil_ni_operation_failed")
					self.show_system_note("%s\n%s" % (errstr, errmsg))
					raise
Beispiel #5
0
	def set_thumbnail(self, filename):
		try:
			filetype = gnomevfs.get_mime_type(filename)
		except:
			filetype = "unknown"
		if filetype.startswith("image") or filetype.startswith("sketch"):
			im = Image.open(filename)
			im.thumbnail((256, 256), Image.NEAREST)
			pixbuf = self.cont.image2pixbuf(im)
			image = gtk.Image()
			image.set_from_pixbuf(pixbuf)
		elif filetype.startswith("audio"):
			icon_theme = gtk.icon_theme_get_default()
			pixbuf = icon_theme.load_icon("mediaplayer_default_album", 128, 0)
			image = gtk.Image()
			image.set_from_pixbuf(pixbuf)			
		elif filetype.startswith("video"):
			icon_theme = gtk.icon_theme_get_default()
			pixbuf = icon_theme.load_icon("general_video", 128, 0)
			image = gtk.Image()
			image.set_from_pixbuf(pixbuf)
		else:
			icon_theme = gtk.icon_theme_get_default()
			pixbuf = icon_theme.load_icon("tasklaunch_file_manager", 128, 0)
			image = gtk.Image()
			image.set_from_pixbuf(pixbuf)
		
		self.imageBox.remove(self.imageBoxContent)
		self.imageBoxContent = image
		self.imageBox.add(self.imageBoxContent)
		self.imageBox.show_all()
		return
Beispiel #6
0
    def resize_img(self, filename):
        """ resize an image """
        """ thanks tomaszf for this function """
        """ slightly modified by frals """
        try:
            img = Image.open(filename)
            log.info("width %s", str(img.size[0]))
            log.info("height %s", str(img.size[1]))
            newWidth = int(self.config.get_img_resize_width())
            if img.size[0] > newWidth:
                newWidth = int(self.config.get_img_resize_width())
                newHeight = int(newWidth * img.size[1] / img.size[0])
                log.info("Resizing image: %s * %s", str(newWidth),
                         str(newHeight))

                # Image.BILINEAR, Image.BICUBIC, Image.ANTIALIASING
                rimg = img.resize((newWidth, newHeight), Image.BILINEAR)
                filename = filename.rpartition("/")
                filename = filename[-1]
                rattachment = self.config.get_imgdir() + filename
                try:
                    rimg.save(rattachment)
                except KeyError:
                    try:
                        mimetype = gnomevfs.get_mime_type(rattachment)
                        extension = mimetype.rpartition("/")[2]
                        rattachment = "%s.%s" % (rattachment, extension)
                    except:
                        log.exception("rimg.save filetype troubles")
                        # we tried our best... lets just go with jpg!
                        rattachment = "%s.jpg" % (rattachment)
                    rimg.save(rattachment)
                self.attachmentIsResized = True
            else:
                rattachment = filename

            return rattachment

        except Exception, e:
            log.exception("resizer: %s %s", type(e), e)
            raise
Beispiel #7
0
	def resize_img(self, filename):
		""" resize an image """
		""" thanks tomaszf for this function """
		""" slightly modified by frals """
		try:
			img = Image.open(filename)
			log.info("width %s", str(img.size[0]))
			log.info("height %s", str(img.size[1]))
			newWidth = int(self.config.get_img_resize_width())
			if img.size[0] > newWidth:
				newWidth = int(self.config.get_img_resize_width())
				newHeight = int(newWidth * img.size[1] / img.size[0])
				log.info("Resizing image: %s * %s", str(newWidth), str(newHeight))

				# Image.BILINEAR, Image.BICUBIC, Image.ANTIALIASING
				rimg = img.resize((newWidth, newHeight), Image.BILINEAR)
				filename = filename.rpartition("/")
				filename = filename[-1]
				rattachment = self.config.get_imgdir() + filename
				try:
					rimg.save(rattachment)
				except KeyError:
					try:
						mimetype = gnomevfs.get_mime_type(rattachment)
						extension = mimetype.rpartition("/")[2]
						rattachment = "%s.%s" % (rattachment, extension)
					except:
						log.exception("rimg.save filetype troubles")
						# we tried our best... lets just go with jpg!
						rattachment = "%s.jpg" % (rattachment)
					rimg.save(rattachment)
				self.attachmentIsResized = True
			else:
				rattachment = filename
				
			return rattachment
		
		except Exception, e:
			log.exception("resizer: %s %s", type(e), e)
			raise
Beispiel #8
0
	def mms_img_clicked(self, widget, data):
		""" action on click on image/button """
		log.info("img clicked: %s", data)
		path = str("file://" + data)
		# gnomevfs seems to be better than mimetype when guessing mimetype for us
		file_mimetype = gnomevfs.get_mime_type(path)
		log.info("path: %s", path)
		log.info("mimetype: %s", file_mimetype)
		if file_mimetype != None:
			if file_mimetype.startswith("video") or file_mimetype.startswith("audio"):
				rpc = osso.Rpc(self.osso_c)
				rpc.rpc_run("com.nokia.mediaplayer", "/com/nokia/mediaplayer", "com.nokia.mediaplayer", "mime_open", (str, path))	
			elif file_mimetype.startswith("image"):
				rpc = osso.Rpc(self.osso_c)
				ret = rpc.rpc_run("com.nokia.image_viewer", "/com/nokia/image_viewer", "com.nokia.image_viewer", "mime_open", (str, path))
			elif "vcard" in file_mimetype:
				rpc = osso.Rpc(self.osso_c)
				ret = rpc.rpc_run("com.nokia.osso_addressbook", "/com/nokia/osso_addressbook", "com.nokia.osso_addressbook", "mime_open", (str, path))
		else:
			# TODO: how to solve this?
			# move .mms to ~/MyDocs? change button to copy file to ~/MyDocs?
			#rpc = osso.Rpc(self.osso_c)
			#path = os.path.dirname(path).replace("file://", "")
			log.info("path %s", str(path))
Beispiel #9
0
    def insert_mms_message(self, pushid, message, direction=MSG_DIRECTION_IN):
        """Takes a MMSMessage object as input, and optionally a MSG_DIRECTION_*
		Returns the newly inserted rows id.
		
		"""
        mmslist = message.headers
        attachments = message.attachments
        c = self.conn.cursor()
        conn = self.conn
        try:
            transid = mmslist['Transaction-Id']
            del mmslist['Transaction-Id']
            if direction == MSG_DIRECTION_OUT:
                basedir = "%s%s" % (self.outdir, transid)
            else:
                basedir = "%s%s" % (self.mmsdir, transid)

            fpath = "%s%s" % (basedir, "/message")
            size = os.path.getsize(fpath)
        except:
            log.exception("Something went wrong when inserting")
            raise
        try:
            time = mmslist['Date']
            del mmslist['Date']
            dateset = True
        except:
            dateset = False
        isread = MSG_UNREAD
        contact = 0
        if dateset == False:
            vals = (pushid, transid, isread, direction, size, contact, fpath)
            c.execute(
                "insert into mms (pushid, transactionid, msg_time, read, direction, size, contact, file) VALUES (?, ?, datetime('now'), ?, ?, ?, ?, ?)",
                vals)
        else:
            vals = (pushid, transid, time, isread, direction, size, contact,
                    fpath)
            c.execute(
                "insert into mms (pushid, transactionid, msg_time, read, direction, size, contact, file) VALUES (?, ?, ?, ?, ?, ?, ?, ?)",
                vals)
        mmsid = c.lastrowid
        conn.commit()
        log.info("inserted row as: %s", mmsid)

        # insert all headers
        for line in mmslist:
            vals = (mmsid, line, self.byteparse_to_unicode(str(mmslist[line])))
            c.execute(
                "insert into mms_headers (mms_id, header, value) VALUES (?, ?, ?)",
                vals)
            conn.commit()
        attachpaths = basedir + "/"
        # insert the attachments
        for line in attachments:
            log.info("inserting attachment: %s", line)
            filetype = gnomevfs.get_mime_type(attachpaths + line)
            (fname, ext) = os.path.splitext(line)
            hidden = 0
            # These files should be "hidden" from the user
            if ext.startswith(".smil") or filetype == "application/smil":
                hidden = 1
            vals = (mmsid, line, hidden)
            c.execute(
                "insert into attachments (mmsidattach, file, hidden) VALUES (?, ?, ?)",
                vals)
            conn.commit()

        try:
            description = self.byteparse_to_unicode(str(mmslist['Subject']))
        except:
            description = ""
            # get the textfiles
            for line in attachments:
                filetype = gnomevfs.get_mime_type(attachpaths + line)
                log.info("filetype: %s", filetype)
                if filetype.startswith("text"):
                    filep = open(attachpaths + line, 'r')
                    description += filep.read()
                    filep.close()

        # insert the message to be shown in the mainview
        vals = (mmsid, "Description", description)
        log.info("inserting description: %s", description)
        c.execute(
            "insert into mms_headers (mms_id, header, value) VALUES (?, ?, ?)",
            vals)
        conn.commit()
        return mmsid
Beispiel #10
0
	def _parse_mms(self, filename, container):
		""" parse mms and push each part to the container 
		    fetches the mms if its not downloaded         """
		hildon.hildon_gtk_window_set_progress_indicator(self.window, 1)
		self.force_ui_update()
		
		if not self.cont.is_fetched_push_by_transid(filename):
			msgstr = gettext.ldgettext('hildon-application-manager', "ai_nw_downloading") % "MMS"
			banner = hildon.hildon_banner_show_information(self.window, "", msgstr)
			self.force_ui_update()
			self.cont.get_mms_from_push(filename)
			self.cont.mark_mms_read(filename)
				

		headerlist = self.cont.get_mms_headers(filename)

		topbox = gtk.HBox()
		
		if self._direction == fMMSController.MSG_DIRECTION_IN:
			label = gtk.Label('<span foreground="#666666">%s</span>' \
					  % gettext.ldgettext('modest', 'mail_va_from'))
			sender = headerlist.get('From', "0").replace("/TYPE=PLMN", "")
		else:
			label = gtk.Label('<span foreground="#666666">%s</span>' \
					  % gettext.ldgettext('rtcom-messaging-ui', 'messaging_fi_new_sms_to'))
			sender = headerlist['To'].replace("/TYPE=PLMN", "")
		
		label.set_use_markup(True)
		label.set_alignment(0, 0.5)

		senderuid = self.ch.get_uid_from_number(sender)
		sendername = self.ch.get_displayname_from_uid(senderuid)
		if sendername != None:
			sender = sendername

		self.window.set_title("MMS - " + str(sender))

		namelabel = gtk.Label(sender)
		namelabel.set_alignment(0, 0.5)

		mtime = headerlist['Time']
		mtime = self.cont.convert_timeformat(mtime, "%Y-%m-%d | %H:%M")
					
		timestring = '<span foreground="#666666">' + mtime + "</span>"
		timelabel = gtk.Label(timestring)
		timelabel.set_use_markup(True)
		timelabel.set_alignment(1, 0.5)

		topbox.pack_start(label, False, False, 0)
		topbox.pack_start(namelabel, True, True, 10)
		topbox.pack_end(timelabel, False, False, 0)
		
		container.pack_start(topbox, False, False, 5)
		sep = gtk.HSeparator()
		container.pack_start(sep, False, False, 0)
		# TODO: add correct padding to first item in next container
				
		self.textview = hildon.TextView()
		self.textview.set_property("name", "hildon-readonly-textview")
		self.textview.set_editable(False)
		self.textview.set_cursor_visible(False)
		self.textview.set_wrap_mode(gtk.WRAP_WORD)
		self.textview.set_justification(gtk.JUSTIFY_LEFT)
		textbuffer = gtk.TextBuffer()
		direction = self.cont.get_direction_mms(filename)
		
		if direction == fMMSController.MSG_DIRECTION_OUT:
			path = self._outdir + filename
		else:
			path = self.cont.get_filepath_for_mms_transid(filename)
		
		filelist = self.cont.get_mms_attachments(filename)
		log.info("filelist: %s", filelist)
		self.attachment = None
		for fname in filelist:
			(name, ext) = os.path.splitext(fname)
			fnpath = os.path.join(path, fname)
			isText = False
			isImage = False
			try:
				filetype = gnomevfs.get_mime_type(fnpath)
				log.info("filetype: %s", filetype)
				if filetype != None:
					if filetype.startswith("image") or filetype.startswith("sketch"):
						isImage = True
					if filetype.startswith("text") and not "x-vcard" in filetype:
						isText = True
			except Exception, e:
				filetype = None
				log.exception("%s %s", type(e), e)

			if isImage or ext == ".wbmp":
				""" insert the image in an eventbox so we can get signals """
				ebox = gtk.EventBox()
				img = gtk.Image()
				#img.set_from_file(path + "/" + fname)
				fullpath = "%s/%s" % (path, fname)
				im = Image.open(fnpath)
				im.thumbnail((384, 384), Image.NEAREST)
				pixbuf = self.cont.image2pixbuf(im)
				img = gtk.Image()
				img.set_from_pixbuf(pixbuf)
				ebox.add(img)
				menu = self.mms_img_menu(fullpath)
				ebox.tap_and_hold_setup(menu)
				container.add(ebox)
				self.attachment = fnpath
			elif isText or ext.startswith(".txt"):
				try:
					fp = codecs.open(path + "/" + fname, 'r', 'utf-8')
					contents = fp.read()
				except:
					fp = codecs.open(path + "/" + fname, 'r', 'latin-1')
					contents = fp.read()
				
				fp.close()
				textbuffer.insert(textbuffer.get_end_iter(), contents)
			elif name != "message" and name != "headers" and not ext.startswith(".smil") and filetype != "application/smil":
				self.attachment = fnpath
				attachButton = hildon.Button(gtk.HILDON_SIZE_FINGER_HEIGHT, hildon.BUTTON_ARRANGEMENT_HORIZONTAL, fname)
				attachButton.connect('clicked', self.mms_img_clicked, fnpath)
				container.pack_end(attachButton, False, False, 0)
Beispiel #11
0
	def insert_mms_message(self, pushid, message, direction=MSG_DIRECTION_IN):
		"""Takes a MMSMessage object as input, and optionally a MSG_DIRECTION_*
		Returns the newly inserted rows id.
		
		"""		
		mmslist = message.headers
		attachments = message.attachments
		c = self.conn.cursor()
		conn = self.conn
		try:
			transid = mmslist['Transaction-Id']
			del mmslist['Transaction-Id']
			if direction == MSG_DIRECTION_OUT:
				basedir = "%s%s" % (self.outdir, transid)
			else:
				basedir = "%s%s" % (self.mmsdir, transid)
			
			fpath = "%s%s" % (basedir, "/message")
			size = os.path.getsize(fpath)
		except:
			log.exception("Something went wrong when inserting")
			raise
		try:
			time = mmslist['Date']
			del mmslist['Date']
			dateset = True
		except:
			dateset = False
		isread = MSG_UNREAD
		contact = 0
		if dateset == False:
			vals = (pushid, transid, isread, direction, size, contact, fpath)
			c.execute("insert into mms (pushid, transactionid, msg_time, read, direction, size, contact, file) VALUES (?, ?, datetime('now'), ?, ?, ?, ?, ?)", vals)
		else:
			vals = (pushid, transid, time, isread, direction, size, contact, fpath)
			c.execute("insert into mms (pushid, transactionid, msg_time, read, direction, size, contact, file) VALUES (?, ?, ?, ?, ?, ?, ?, ?)", vals)
		mmsid = c.lastrowid
		conn.commit()
		log.info("inserted row as: %s", mmsid)
		
		# insert all headers
		for line in mmslist:
			vals = (mmsid, line, self.byteparse_to_unicode(str(mmslist[line])))
			c.execute("insert into mms_headers (mms_id, header, value) VALUES (?, ?, ?)", vals)
			conn.commit()
		attachpaths = basedir + "/"
		# insert the attachments
		for line in attachments:
			log.info("inserting attachment: %s", line)
			filetype = gnomevfs.get_mime_type(attachpaths + line)
			(fname, ext) = os.path.splitext(line)
			hidden = 0
			# These files should be "hidden" from the user
			if ext.startswith(".smil") or filetype == "application/smil":
				hidden = 1
			vals = (mmsid, line, hidden)
			c.execute("insert into attachments (mmsidattach, file, hidden) VALUES (?, ?, ?)", vals)
			conn.commit()
		
		try:
			description = self.byteparse_to_unicode(str(mmslist['Subject']))
		except:
			description = ""			
			# get the textfiles
			for line in attachments:
				filetype = gnomevfs.get_mime_type(attachpaths + line)
				log.info("filetype: %s", filetype)
				if filetype.startswith("text"):
					filep = open(attachpaths + line, 'r')
					description += filep.read()
					filep.close()
			

		# insert the message to be shown in the mainview
		vals = (mmsid, "Description", description)
		log.info("inserting description: %s", description)
		c.execute("insert into mms_headers (mms_id, header, value) VALUES (?, ?, ?)", vals)
		conn.commit()
		return mmsid