-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathcloudhandle.py
More file actions
executable file
·93 lines (76 loc) · 3.1 KB
/
cloudhandle.py
File metadata and controls
executable file
·93 lines (76 loc) · 3.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# -*- coding: utf-8 -*-
#Copyright (C)2010 Abhinandh <abhinandh@gmail.com>
#This Program in licenser under General Public License Ver 3
from PyQt4.QtCore import QThread, QObject, pyqtSignal, QFileInfo, QString, QUrl
from cloud_api import CloudApi
import urlparse
from preferences import PreferencesDialog
class CloudHandle(object):
fileList = []
def __init__(self):
self.pdialog = PreferencesDialog()
self.pdialog.signals.settingsChanged.connect(self.initializeApi)
self.signals = self.Signals()
self.initializeApi()
def initializeApi(self):
self.connected = False
try:
username = self.pdialog.settings['username']
password = self.pdialog.settings['password']
if username == '' or password == '':
raise ValueError('Empty password or username')
self.api = CloudApi(username, password)
self.getFileList()
except (KeyError, ValueError):
self.pdialog.show()
print "Error reading settings"
def getFileList(self):
self.api.getFileList(self.pdialog.settings['list_size'], self.gotFileList)
def gotFileList(self, l):
self.connected = True
self.fileList = l
self.signals.gotFileList.emit(l)
def addItem(self, url):
url = str(url)
if urlparse.urlparse(url).scheme == "file":
self.api.uploadFile(url, self.itemAdded)
else:
self.api.bookmark(url, self.itemAdded)
self.signals.uploadStarted.emit()
def itemAdded(self, item):
self.fileList.insert(0, item)
self.fileList.pop()
self.signals.gotFileList.emit(self.fileList)
if self.pdialog.settings['auto_clipboard']:
self.signals.loadClipboard.emit(item['url'])
if self.pdialog.settings['notifications']:
if item['item_type'] == 'bookmark':
self.notify('Bookmarked - '+item['name'], item['url'])
else:
self.notify('File Uploaded - '+item['name'], item['url'])
self.signals.uploadFinished.emit()
def deleteItem(self, url):
url = str(url)
self.api.delete(url, self.deleted)
def deleted(self, x):
self.getFileList()
if self.pdialog.settings['notifications']:
self.notify("Deleted - "+x['name'], 'This item was removed from your CloudApp')
def showPreferences(self):
self.pdialog.show()
def notify(self, title, text, icon=None):
try:
import pynotify
if pynotify.init("Cloud App"):
n = pynotify.Notification(title, text)
n.set_timeout(5)
n.show()
else:
print "there was a problem initializing the pynotify module"
except:
print "you don't seem to have pynotify installed"
class Signals(QObject):
gotFileList = pyqtSignal(list)
loadClipboard = pyqtSignal(str)
uploadStarted = pyqtSignal()
uploadFinished = pyqtSignal()