1
# -*- coding: utf-8 -*-
3
# Authors: Natalia B. Bidart <natalia.bidart@canonical.com>
5
# Copyright 2011 Canonical Ltd.
7
# This program is free software: you can redistribute it and/or modify it
8
# under the terms of the GNU General Public License version 3, as published
9
# by the Free Software Foundation.
11
# This program is distributed in the hope that it will be useful, but
12
# WITHOUT ANY WARRANTY; without even the implied warranties of
13
# MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
14
# PURPOSE. See the GNU General Public License for more details.
16
# You should have received a copy of the GNU General Public License along
17
# with this program. If not, see <http://www.gnu.org/licenses/>.
19
"""The user interface for the control panel for Ubuntu One."""
21
from __future__ import division
25
from PyQt4 import QtGui, QtCore
26
from twisted.internet import defer
28
from ubuntuone.controlpanel import backend
29
from ubuntuone.controlpanel.logger import setup_logging
30
from ubuntuone.controlpanel.gui import (
35
logger = setup_logging('qt.addfolder')
37
CLOSE = QtGui.QMessageBox.Close
40
class AddFolderButton(QtGui.QPushButton):
41
"""The AddFolderButton widget"""
43
folderCreated = QtCore.pyqtSignal(unicode)
44
folderCreationCanceled = QtCore.pyqtSignal()
46
def __init__(self, *args, **kwargs):
47
"""Initialize the UI of the widget."""
48
super(AddFolderButton, self).__init__(*args, **kwargs)
49
self.cloud_folders = []
50
self.backend = backend.ControlBackend()
51
self.clicked.connect(self.on_clicked)
52
logger.debug('%s: started.', self.__class__.__name__)
55
@defer.inlineCallbacks
57
"""The 'Sync another folder' button was clicked."""
58
folder = QtGui.QFileDialog.getExistingDirectory(parent=self)
59
folder = unicode(folder)
60
logger.debug('on_add_folder_button_clicked: user requested folder '
61
'creation for path %r', folder)
63
self.folderCreationCanceled.emit()
66
is_valid = yield self.backend.validate_path_for_folder(folder)
68
user_home = os.path.expanduser('~')
69
text = FOLDER_INVALID_PATH % {'folder_path': folder,
70
'home_folder': user_home}
71
QtGui.QMessageBox.warning(self, '', text, CLOSE)
74
yield self.backend.create_folder(folder_path=folder)
75
self.folderCreated.emit(folder)