updated on Fri Jan 13 20:02:10 UTC 2012
[aur-mirror.git] / qweborf / qweborf.py
blob493c7d8bdd5495de92766df7e0b883157953c5b4
1 #!/usr/bin/env python
2 # -*- coding: utf-8 -*-
3 # Weborf
4 # Copyright (C) 2010 Salvo "LtWorf" Tomaselli
5 #
6 # Weborf is free software: you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation, either version 3 of the License, or
9 # (at your option) any later version.
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program. If not, see <http://www.gnu.org/licenses/>.
19 # author Salvo "LtWorf" Tomaselli <tiposchi@tiscali.it>
21 from PyQt4 import QtCore, QtGui
22 import main
23 import whelper
24 import nhelper
25 import sys
26 import os
28 class qweborfForm (QtGui.QWidget):
29 '''This class is the form used for the survey, needed to intercept the events.
30 It also sends the data with http POST to a page hosted on galileo'''
32 DBG_DEFAULT=0
33 DBG_WARNING=1
34 DBG_ERROR=2
35 DBG_NOTICE=3
37 def setUi(self,ui):
38 self.ui=ui
39 self.weborf=whelper.weborf_runner(self)
40 self.started=False
42 if self.weborf.version>= '0.13':
43 self.ui.chkTar.setEnabled(True)
44 else:
45 self.ui.chkTar.setEnabled(False)
47 #Listing addresses
48 for i in nhelper.getaddrs(self.weborf.ipv6):
49 self.ui.cmbAddress.addItem(i,None)
51 self.defaultdir=str(QtGui.QDesktopServices.storageLocation(QtGui.QDesktopServices.HomeLocation))
52 self.ui.txtPath.setText(self.defaultdir)
54 def logger(self,data,level=DBG_DEFAULT):
55 '''logs an entry, showing it in the GUI'''
56 if level==self.DBG_WARNING:
57 data='<font color="orange"><strong>WARNING</strong></font>: %s' % data
58 elif level==self.DBG_ERROR:
59 data='<font color="red"><strong>ERROR</strong></font>: %s' % data
60 elif level==self.DBG_NOTICE:
61 data='<font color="green"><strong>NOTICE</strong></font>: %s' % data
62 self.ui.txtLog.moveCursor(QtGui.QTextCursor.End)
63 self.ui.txtLog.insertHtml(data+'<br>')
64 self.ui.txtLog.moveCursor(QtGui.QTextCursor.End)
66 def setDefaultValues(self):
67 '''Sets default values into the form GUI. It has to be
68 called after the form has been initialized'''
69 pass
71 def stop_sharing(self):
72 if self.weborf.stop():
73 self.ui.cmdStart.setEnabled(True)
74 self.ui.cmdStop.setEnabled(False)
75 self.ui.tabWidget.setEnabled(True)
76 self.started=False
77 def about(self):
79 self.logger('<hr><strong>Qweborf 0.13</strong>')
80 self.logger('This program comes with ABSOLUTELY NO WARRANTY.'
81 ' This is free software, and you are welcome to redistribute it under certain conditions.'
82 ' For details see the <a href="http://www.gnu.org/licenses/gpl.html">GPLv3 Licese</a>.')
83 self.logger('<a href="http://galileo.dmi.unict.it/wiki/weborf">Homepage</a>')
84 self.logger('Salvo \'LtWorf\' Tomaselli <a href="mailto:tiposchi@tiscali.it">&lt;tiposchi@tiscali.it&gt;</a>')
86 def terminate(self):
87 if self.started:
88 self.stop_sharing()
89 sys.exit(0)
91 def start_sharing(self):
93 options={} #Dictionary with the chosen options
95 options['path']=self.ui.txtPath.text()
97 if self.ui.chkEnableAuth.isChecked():
98 options['username']=self.ui.txtUsername.text()
99 options['password']=self.ui.txtPassword.text()
100 else:
101 options['username']=None
102 options['password']=None
104 options['port'] = self.ui.spinPort.value()
106 options['dav'] = self.ui.chkDav.isChecked()
107 if self.ui.chkDav.isChecked():
108 options['write'] = self.ui.chkWrite.isChecked()
109 else:
110 options['write'] = False
112 options['tar'] = self.ui.chkTar.isChecked()
114 if self.ui.cmbAddress.currentIndex()==0:
115 options['ip']=None
116 else:
117 options['ip']=str(self.ui.cmbAddress.currentText())
119 if self.weborf.start(options):
120 self.ui.cmdStart.setEnabled(False)
121 self.ui.cmdStop.setEnabled(True)
122 self.ui.tabWidget.setEnabled(False)
123 self.started=True
126 def select_path(self):
127 #filename = QtGui.QFileDialog
128 #dial=QtGui.QFileDialog()
129 dirname= QtGui.QFileDialog.getExistingDirectory(
130 self,
131 QtGui.QApplication.translate("Form", "Directory to share", None, QtGui.QApplication.UnicodeUTF8),
132 self.defaultdir,
133 QtGui.QFileDialog.ShowDirsOnly
136 self.ui.txtPath.setText(dirname)
138 def q_main():
139 import sys
140 app = QtGui.QApplication(sys.argv)
141 Form = qweborfForm()
142 ui = main.Ui_Form()
143 ui.setupUi(Form)
144 Form.setUi(ui)
145 Form.show()
146 res=app.exec_()
147 Form.terminate()
148 sys.exit(res)
150 if __name__ == "__main__":
151 q_main()