2 # -*- coding: utf-8 -*-
4 # Copyright (C) 2010 Salvo "LtWorf" Tomaselli
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
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'''
39 self
.weborf
=whelper
.weborf_runner(self
)
42 if self
.weborf
.version
>= '0.13':
43 self
.ui
.chkTar
.setEnabled(True)
45 self
.ui
.chkTar
.setEnabled(False)
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'''
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)
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"><tiposchi@tiscali.it></a>')
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()
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()
110 options
['write'] = False
112 options
['tar'] = self
.ui
.chkTar
.isChecked()
114 if self
.ui
.cmbAddress
.currentIndex()==0:
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)
126 def select_path(self
):
127 #filename = QtGui.QFileDialog
128 #dial=QtGui.QFileDialog()
129 dirname
= QtGui
.QFileDialog
.getExistingDirectory(
131 QtGui
.QApplication
.translate("Form", "Directory to share", None, QtGui
.QApplication
.UnicodeUTF8
),
133 QtGui
.QFileDialog
.ShowDirsOnly
136 self
.ui
.txtPath
.setText(dirname
)
140 app
= QtGui
.QApplication(sys
.argv
)
150 if __name__
== "__main__":