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):
36 def __init__(self, listing):
37 QtCore.QObject.__init__(self)
38 from XmlHandler import XmlHandler
39 self._handler = XmlHandler(listing)
41 def update_progress(self, percent_complete,
42 completed, in_progress, queued,
43 bytes_downloaded, bytes_updated, bytes_per_second,
45 total = completed + in_progress + queued
46 root.updateProgress(int(total), int(completed))
48 def articleCountUpdated(self):
49 print "article updated"
51 def update_started(self):
54 def update_finished(self):
57 @QtCore.Slot(str,str, result=str)
58 def getArticle(self, key, article):
59 feed = listing.getFeed(key)
61 file = codecs.open(feed.getContentLink(article), "r", "utf-8")
62 html = file.read().replace("body", "body bgcolor='#ffffff'", 1)
65 html = u"<html><body>Error retrieving article</body></html>"
68 @QtCore.Slot(str, result=str)
69 def getFeedsXml(self, catid):
70 return self._handler.generateFeedsXml(catid)
72 @QtCore.Slot(str,result=str)
73 def getArticlesXml(self, key):
74 feed = listing.getFeed(key)
75 self.cachedList = feed.getIds(onlyUnread=True)
76 #onlyUnread = arguments.get("onlyUnread","False")
77 return self._handler.generateArticlesXml(key, config.getHideReadArticles())
79 @QtCore.Slot(str,str,bool,result=str)
80 def getNextId(self, key, articleid, onlyUnread):
82 print self.cachedList, articleid
83 index = self.cachedList.index(articleid)
84 return self.cachedList[(index + 1) % len(self.cachedList)]
86 feed = listing.getFeed(key)
87 return feed.getNextId(articleid)
89 @QtCore.Slot(str,str,bool,result=str)
90 def getPreviousId(self, key, articleid, onlyUnread):
92 print self.cachedList, articleid
93 index = self.cachedList.index(articleid)
94 return self.cachedList[(index - 1) % len(self.cachedList)]
96 feed = listing.getFeed(key)
97 return feed.getPreviousId(articleid)
99 @QtCore.Slot(result=str)
100 def getCategoryXml(self):
101 return self._handler.generateCategoryXml()
103 @QtCore.Slot(QtCore.QObject)
104 def feedClicked(self, wrapper):
105 #print 'User clicked on:', wrapper._key
106 #articlesModel.updateModel(wrapper._key)
110 def updateFeed(self, key):
111 listing.updateFeed(key)
115 for catid in listing.getListOfCategories():
116 for feed in listing.getSortedListOfKeys("Manual", category=catid):
117 listing.updateFeed(feed)
120 def updateCategory(self, catid):
121 for feed in listing.getSortedListOfKeys("Manual", category=catid):
122 listing.updateFeed(feed)
124 @QtCore.Slot(str,str,str)
125 def addFeed(self, title, url, catid):
126 listing.addFeed(title,url, category=catid)
129 def addCategory(self, name):
130 listing.addCategory(name)
133 def removeFeed(self, key):
134 listing.removeFeed(key)
137 def removeCategory(self, catid):
138 listing.removeCategory(catid)
141 def markAllAsRead(self, key):
142 feed = listing.getFeed(key)
144 listing.updateUnread(key)
146 @QtCore.Slot(str, str)
147 def setEntryRead(self, key, articleid):
148 feed = listing.getFeed(key)
149 feed.setEntryRead(articleid)
150 listing.updateUnread(key)
152 @QtCore.Slot(str, result=str)
153 def getConfig(self, item):
154 if (item == "hideReadFeed"):
156 if (item == "hideReadArticles"):
160 @QtCore.Slot(str, str)
161 def populateFileDialog(self, path, type):
164 for file in glob.glob(path+type):
166 root.addFileNotification(file, os.path.basename(file))
168 @QtCore.Slot(str, result=int)
169 def importOpml(self, filename):
170 from opml_lib import parseOpml
171 file = open(filename, "r")
172 feeds = parseOpml(file.read())
174 for (title, url) in feeds:
175 listing.addFeed(title, url)
178 @QtCore.Slot(str, result=str)
179 def exportOpml(self, filename="/home/user/MyDocs/feedingit-export.opml"):
180 logger.debug("ExportOpmlData: %s" % filename)
181 from opml_lib import getOpmlText
183 str = getOpmlText(listing)
184 file = open(filename, "w")
189 logger.debug("Error exporting: %s" % filename)
192 @QtCore.Slot(str, result=bool)
193 def getBooleanSetting(self, setting):
194 if (setting == "theme"):
195 return config.getTheme()
196 elif (setting == "imageCache" ):
197 return config.getImageCache()
198 elif (setting == "hideReadFeeds"):
199 return config.getHideReadFeeds()
200 elif (setting == "hideReadArticles"):
201 return config.getHideReadArticles()
202 elif (setting == "autoupdate"):
203 return config.isAutoUpdateEnabled()
207 @QtCore.Slot(str, result=int)
208 def getIntSetting(self, setting):
209 if (setting == "artFontSize"):
210 return config.getArtFontSize()
211 elif (setting == "fontSize" ):
212 return config.getFontSize()
216 @QtCore.Slot(str, bool)
217 def setBooleanSetting(self, setting, value):
218 if (setting == "theme"):
219 config.setTheme(value)
220 elif (setting == "imageCache" ):
221 config.setImageCache(value)
222 elif (setting == "hideReadFeeds"):
223 config.setHideReadFeeds(value)
224 elif (setting == "hideReadArticles"):
225 config.setHideReadArticles(value)
226 elif (setting == "autoupdate"):
227 config.setAutoUpdateEnabled(value)
230 @QtCore.Slot(str, int)
231 def setIntSetting(self, setting, value):
232 if (setting == "artFontSize"):
233 config.setArtFontSize(value)
234 elif (setting == "fontSize" ):
235 config.setFontSize(value)
238 @QtCore.Slot(str, str)
239 def openSettings(self):
240 bus = dbus.SessionBus()
241 settingService = bus.get_object('com.nokia.DuiControlPanel', '/')
242 setting = shareService.get_dbus_method('appletPage', 'com.nokia.DuiControlPanelIf')
243 setting("feedingitsync")
245 @QtCore.Slot(str, str)
246 def share(self, key, articleid):
247 feed = listing.getFeed(key)
248 title = feed.getTitle(articleid)
249 link = feed.getExternalLink(articleid)
250 description = 'Shared%20via%20FeedingIt%20on%20Meego'
252 bus = dbus.SessionBus()
253 shareService = bus.get_object('com.nokia.ShareUi', '/')
254 share = shareService.get_dbus_method('share', 'com.nokia.maemo.meegotouch.ShareUiInterface')
255 #share([u'data:text/x-url;description=Support%20for%20Nokia%20Developers;title=Forum%20Nokia,http%3A%2F%2Fforum.nokia.com',])
256 share( ['data:text/x-url;title=%s;description=%s,%s' %(urllib.quote(title), description, urllib.quote(link)),] )
259 if not isdir(CONFIGDIR):
263 logger.error("Error: Can't create configuration directory")
267 from config import Config
269 config = Config(None,CONFIGDIR+"config.ini")
272 listing = Listing(config, CONFIGDIR)
277 from jobmanager import JobManager
280 app = QtGui.QApplication(sys.argv)
281 view = QtDeclarative.QDeclarativeView()
283 controller = Controller(listing)
285 # listen on dbus for download update progress
286 bus = dbus.SessionBus()
288 bus.add_signal_receiver(handler_function=controller.update_progress,
290 signal_name='UpdateProgress',
291 dbus_interface='org.marcoz.feedingit',
292 path='/org/marcoz/feedingit/update')
294 bus.add_signal_receiver(handler_function=controller.articleCountUpdated,
296 signal_name='ArticleCountUpdated',
297 dbus_interface='org.marcoz.feedingit',
298 path='/org/marcoz/feedingit/update')
299 bus.add_signal_receiver(handler_function=controller.update_started,
301 signal_name='UpdateStarted',
302 dbus_interface='org.marcoz.feedingit',
303 path='/org/marcoz/feedingit/update')
304 bus.add_signal_receiver(handler_function=controller.update_finished,
306 signal_name='UpdateFinished',
307 dbus_interface='org.marcoz.feedingit',
308 path='/org/marcoz/feedingit/update')
311 rc = view.rootContext()
313 rc.setContextProperty('controller', controller)
315 # Comment the two lines below if you don't want to use OpenGL for QML rendering or if it is not supported
316 #glw = QtOpenGL.QGLWidget()
317 #view.setViewport(glw)
319 if os.path.exists('/usr/share/feedingit/qml'):
320 glw = QtOpenGL.QGLWidget()
321 view.setViewport(glw)
322 view.setSource('/usr/share/feedingit/qml/main.qml')
323 view.showFullScreen()
325 view.setSource(os.path.join('qml','main.qml'))
327 #view.setSource(os.path.join('qml','FeedingIt.qml'))
328 root = view.rootObject()
330 #view.showFullScreen()
332 sys.exit(app.exec_())
334 if __name__ == "__main__":