5 from PySide import QtGui
6 from PySide import QtDeclarative
8 from os import mkdir, remove, stat, environ
9 from os.path import isfile, isdir, exists
12 # import python dbus GLib mainloop support
13 import dbus.mainloop.glib
14 # Enable glib main loop support
15 dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
17 # Comment the line below if you don't want to use OpenGL for QML rendering or if it is not supported
18 from PySide import QtOpenGL, QtCore
20 from rss_sqlite import Listing
21 CONFIGDIR = environ.get("HOME", "/home/user") + "/.feedingit/"
22 #CONFIGDIR = "/home/user/.feedingit"
25 logger = logging.getLogger(__name__)
28 debugging.init(dot_directory=".feedingit", program_name="feedingit-pyside")
30 from cgi import escape
33 class Controller(QtCore.QObject):
35 def __init__(self, listing):
36 QtCore.QObject.__init__(self)
37 from XmlHandler import XmlHandler
38 self._handler = XmlHandler(listing)
40 def update_progress(self, percent_complete,
41 completed, in_progress, queued,
42 bytes_downloaded, bytes_updated, bytes_per_second,
44 total = completed + in_progress + queued
45 root.updateProgress(int(total), int(completed))
47 def articleCountUpdated(self):
48 print "article updated"
50 def update_started(self):
53 def update_finished(self):
56 @QtCore.Slot(str,str, result=str)
57 def getArticle(self, key, article):
58 feed = listing.getFeed(key)
60 file = codecs.open(feed.getContentLink(article), "r", "utf-8")
61 html = file.read().replace("body", "body bgcolor='#ffffff'", 1)
64 html = u"<html><body>Error retrieving article</body></html>"
67 @QtCore.Slot(str, result=str)
68 def getFeedsXml(self, catid):
69 return self._handler.generateFeedsXml(catid)
71 @QtCore.Slot(str,result=str)
72 def getArticlesXml(self, key):
73 #onlyUnread = arguments.get("onlyUnread","False")
74 return self._handler.generateArticlesXml(key, config.getHideReadArticles())
76 @QtCore.Slot(result=str)
77 def getCategoryXml(self):
78 return self._handler.generateCategoryXml()
80 @QtCore.Slot(QtCore.QObject)
81 def feedClicked(self, wrapper):
82 #print 'User clicked on:', wrapper._key
83 #articlesModel.updateModel(wrapper._key)
87 def updateFeed(self, key):
88 listing.updateFeed(key)
92 for catid in listing.getListOfCategories():
93 for feed in listing.getSortedListOfKeys("Manual", category=catid):
94 listing.updateFeed(feed)
97 def updateCategory(self, catid):
98 for feed in listing.getSortedListOfKeys("Manual", category=catid):
99 listing.updateFeed(feed)
101 @QtCore.Slot(str,str,str)
102 def addFeed(self, title, url, catid):
103 listing.addFeed(title,url, category=catid)
106 def addCategory(self, name):
107 listing.addCategory(name)
110 def removeFeed(self, key):
111 listing.removeFeed(key)
114 def removeCategory(self, catid):
115 listing.removeCategory(catid)
118 def markAllAsRead(self, key):
119 feed = listing.getFeed(key)
121 listing.updateUnread(key)
123 @QtCore.Slot(str, str)
124 def setEntryRead(self, key, articleid):
125 feed = listing.getFeed(key)
126 feed.setEntryRead(articleid)
127 listing.updateUnread(key)
129 @QtCore.Slot(str, result=str)
130 def getConfig(self, item):
131 if (item == "hideReadFeed"):
133 if (item == "hideReadArticles"):
137 @QtCore.Slot(str, str)
138 def populateFileDialog(self, path, type):
141 for file in glob.glob(path+type):
143 root.addFileNotification(file, os.path.basename(file))
145 @QtCore.Slot(str, result=int)
146 def importOpml(self, filename):
147 from opml_lib import parseOpml
148 file = open(filename, "r")
149 feeds = parseOpml(file.read())
151 for (title, url) in feeds:
152 listing.addFeed(title, url)
155 @QtCore.Slot(str, result=str)
156 def exportOpml(self, filename="/home/user/MyDocs/feedingit-export.opml"):
157 logger.debug("ExportOpmlData: %s" % filename)
158 from opml_lib import getOpmlText
160 str = getOpmlText(listing)
161 file = open(filename, "w")
166 logger.debug("Error exporting: %s" % filename)
169 @QtCore.Slot(str, result=bool)
170 def getBooleanSetting(self, setting):
171 if (setting == "theme"):
172 return config.getTheme()
173 elif (setting == "imageCache" ):
174 return config.getImageCache()
175 elif (setting == "hideReadFeeds"):
176 return config.getHideReadFeeds()
177 elif (setting == "hideReadArticles"):
178 return config.getHideReadArticles()
179 elif (setting == "autoupdate"):
180 return config.isAutoUpdateEnabled()
184 @QtCore.Slot(str, bool)
185 def setBooleanSetting(self, setting, value):
186 if (setting == "theme"):
187 config.setTheme(value)
188 elif (setting == "imageCache" ):
189 config.setImageCache(value)
190 elif (setting == "hideReadFeeds"):
191 config.setHideReadFeeds(value)
192 elif (setting == "hideReadArticles"):
193 config.setHideReadArticles(value)
194 elif (setting == "autoupdate"):
195 config.setAutoUpdateEnabled(value)
198 @QtCore.Slot(str, str)
199 def share(self, key, articleid):
200 feed = listing.getFeed(key)
201 title = feed.getTitle(articleid)
202 link = feed.getExternalLink(articleid)
203 description = 'Shared%20via%20FeedingIt%20on%20Meego'
205 bus = dbus.SessionBus()
206 shareService = bus.get_object('com.nokia.ShareUi', '/')
207 share = shareService.get_dbus_method('share', 'com.nokia.maemo.meegotouch.ShareUiInterface')
208 #share([u'data:text/x-url;description=Support%20for%20Nokia%20Developers;title=Forum%20Nokia,http%3A%2F%2Fforum.nokia.com',])
209 share( ['data:text/x-url;title=%s;description=%s,%s' %(urllib.quote(title), description, urllib.quote(link)),] )
212 if not isdir(CONFIGDIR):
216 logger.error("Error: Can't create configuration directory")
220 from config import Config
222 config = Config(None,CONFIGDIR+"config.ini")
225 listing = Listing(config, CONFIGDIR)
230 from jobmanager import JobManager
233 app = QtGui.QApplication(sys.argv)
234 view = QtDeclarative.QDeclarativeView()
236 controller = Controller(listing)
238 # listen on dbus for download update progress
239 bus = dbus.SessionBus()
241 bus.add_signal_receiver(handler_function=controller.update_progress,
243 signal_name='UpdateProgress',
244 dbus_interface='org.marcoz.feedingit',
245 path='/org/marcoz/feedingit/update')
247 bus.add_signal_receiver(handler_function=controller.articleCountUpdated,
249 signal_name='ArticleCountUpdated',
250 dbus_interface='org.marcoz.feedingit',
251 path='/org/marcoz/feedingit/update')
252 bus.add_signal_receiver(handler_function=controller.update_started,
254 signal_name='UpdateStarted',
255 dbus_interface='org.marcoz.feedingit',
256 path='/org/marcoz/feedingit/update')
257 bus.add_signal_receiver(handler_function=controller.update_finished,
259 signal_name='UpdateFinished',
260 dbus_interface='org.marcoz.feedingit',
261 path='/org/marcoz/feedingit/update')
264 rc = view.rootContext()
266 rc.setContextProperty('controller', controller)
268 # Comment the two lines below if you don't want to use OpenGL for QML rendering or if it is not supported
269 #glw = QtOpenGL.QGLWidget()
270 #view.setViewport(glw)
272 if os.path.exists('/usr/share/feedingit/qml'):
273 glw = QtOpenGL.QGLWidget()
274 view.setViewport(glw)
275 view.setSource('/usr/share/feedingit/qml/main.qml')
276 view.showFullScreen()
278 view.setSource(os.path.join('qml','main.qml'))
280 #view.setSource(os.path.join('qml','FeedingIt.qml'))
281 root = view.rootObject()
283 #view.showFullScreen()
285 sys.exit(app.exec_())
287 if __name__ == "__main__":