def _show_via_journal(self, url): """Ask the journal to display a URL""" import os import time from sugar import profile from sugar.activity.activity import show_object_in_journal from sugar.datastore import datastore logger.debug('Create journal entry for URL: %s', url) jobject = datastore.create() metadata = { 'title': "%s: %s" % (_('URL from Chat'), url), 'title_set_by_user': '******', 'icon-color': profile.get_color().to_string(), 'mime_type': 'text/uri-list', } for k, v in metadata.items(): jobject.metadata[k] = v file_path = os.path.join(get_activity_root(), 'instance', '%i_' % time.time()) open(file_path, 'w').write(url + '\r\n') os.chmod(file_path, 0755) jobject.set_file_path(file_path) datastore.write(jobject) show_object_in_journal(jobject.object_id) jobject.destroy() os.unlink(file_path)
def open_url(self, url): """Ask the journal to open an URL for us.""" from sugar import profile from shutil import rmtree from sugar.datastore import datastore from sugar.activity.activity import show_object_in_journal from tempfile import mkdtemp tmpfolder = mkdtemp('.tmp', 'url', os.path.join(self.get_activity_root(), 'instance')) tmpfilepath = os.path.join(tmpfolder, 'url') try: tmpfile = open(tmpfilepath, 'w') tmpfile.write(url) tmpfile.close() os.chmod(tmpfolder, 0755) os.chmod(tmpfilepath, 0755) jobject = datastore.create() metadata = { 'title': url, 'title_set_by_user': '******', 'buddies': '', 'preview': '', 'icon-color': profile.get_color().to_string(), 'mime_type': 'text/uri-list', } for k, v in metadata.items(): jobject.metadata[k] = v # the dict.update method is missing =( jobject.file_path = tmpfilepath datastore.write(jobject) show_object_in_journal(jobject.object_id) jobject.destroy() finally: rmtree(tmpfilepath, ignore_errors=True) # clean up!
def journal_show_object(self, object_id): """Invoke journal_show_object from sugar.activity.activity if it exists.""" try: from sugar.activity.activity import show_object_in_journal show_object_in_journal(object_id) except ImportError: pass # no love from sugar.
def show_in_journal(self): '''send the generated .xo bundle to the journal''' jobject = datastore.create() jobject.metadata['title'] = self.title jobject.metadata['mime_type'] = 'application/vnd.olpc-sugar' jobject.metadata['icon-color'] = profile.get_color().to_string() jobject.file_path = self.xo_path datastore.write(jobject) activity.show_object_in_journal(jobject.object_id)
def __subscription_cb(self, source, cb_condition): try: event = self._subscription.pull() if event is not None: event_type = event['event'] if event_type == 'show_journal': show_object_in_journal(event['uid']) elif event_type == 'launch' and event['state'] == 'failure': if not self._sn_plugin_started: ReportWindow(self._client, event).show() except Exception: logging.exception('Cannot dispatch %r event', event) return True
def save_document(self): logging.debug('Saving document to %s' % bundle_path) cls = components.classes[ \ '@mozilla.org/embedding/browser/nsWebBrowserPersist;1'] persist = cls.createInstance(interfaces.nsIWebBrowserPersist) persist.persistFlags = interfaces.nsIWebBrowserPersist \ .PERSIST_FLAGS_REPLACE_EXISTING_FILES local = components.classes["@mozilla.org/file/local;1"] local_file = local.createInstance(interfaces.nsILocalFile) local_data = local.createInstance(interfaces.nsILocalFile) temp_dir = tempfile.mkdtemp() local_file.initWithPath(os.path.join(temp_dir, 'index.html')) local_data.initWithPath(os.path.join(temp_dir, 'data')) persist.saveDocument(self._browser.dom_window.document, local_file, local_data, None, 0, 0) bundle_path = os.path.join(temp_dir, 'bundle.jar') bundle = zipfile.ZipFile(bundle_path, 'w') bundle.write(local_file.path) for i in os.listdir(local_data.path): bundle.write(os.path.join(local_data.path, i), zipfile.ZIP_DEFLATED) bundle.close() jobject = datastore.create() jobject.metadata['title'] = self.title jobject.metadata['mime_type'] = 'application/zip' jobject.metadata['icon-color'] = profile.get_color().to_string() jobject.metadata['activity'] = 'org.laptop.WebActivity' jobject.file_path = bundle_path datastore.write(jobject) activity.show_object_in_journal(jobject.object_id) # cleanup shutil.rmtree(temp_dir)
def _show_via_journal(self, url): """Ask the journal to display a URL""" logging.debug('Create journal entry for URL: %s', url) jobject = datastore.create() metadata = { 'title': "%s: %s" % (_('URL from Chat'), url), 'title_set_by_user': '******', 'icon-color': profile.get_color().to_string(), 'mime_type': 'text/uri-list', } for k, v in metadata.items(): jobject.metadata[k] = v file_path = join(get_activity_root(), 'instance', '%i_' % time.time()) open(file_path, 'w').write(url + '\r\n') os.chmod(file_path, 0755) jobject.set_file_path(file_path) datastore.write(jobject) show_object_in_journal(jobject.object_id) jobject.destroy() os.unlink(file_path)
def response_cb(alert, response_id): if response_id is gtk.RESPONSE_APPLY: activity.show_object_in_journal(dsobject.object_id) self.remove_alert(alert)
def __stop_response_cb(self, alert, response_id): global _active_downloads if response_id is gtk.RESPONSE_APPLY: logging.debug('Start application with downloaded object') activity.show_object_in_journal(self._object_id) self._activity.remove_alert(alert)