~dobey/ubuntu/oneiric/ubuntuone-control-panel/release-113

« back to all changes in this revision

Viewing changes to ubuntuone/controlpanel/gui/qt/addfolder.py

  • Committer: Sebastien Bacher
  • Date: 2011-07-25 13:17:38 UTC
  • mfrom: (25.1.2 ubuntuone-control-panel)
  • Revision ID: seb128@ubuntu.com-20110725131738-yuevatnd859d1phs
Tags: 1.1.1-0ubuntu1
releasing version 1.1.1-0ubuntu1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# -*- coding: utf-8 -*-
 
2
 
 
3
# Authors: Natalia B. Bidart <natalia.bidart@canonical.com>
 
4
#
 
5
# Copyright 2011 Canonical Ltd.
 
6
#
 
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.
 
10
#
 
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.
 
15
#
 
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/>.
 
18
 
 
19
"""The user interface for the control panel for Ubuntu One."""
 
20
 
 
21
from __future__ import division
 
22
 
 
23
import os
 
24
 
 
25
from PyQt4 import QtGui, QtCore
 
26
from twisted.internet import defer
 
27
 
 
28
from ubuntuone.controlpanel import backend
 
29
from ubuntuone.controlpanel.logger import setup_logging
 
30
from ubuntuone.controlpanel.gui import (
 
31
    FOLDER_INVALID_PATH,
 
32
)
 
33
 
 
34
 
 
35
logger = setup_logging('qt.addfolder')
 
36
 
 
37
CLOSE = QtGui.QMessageBox.Close
 
38
 
 
39
 
 
40
class AddFolderButton(QtGui.QPushButton):
 
41
    """The AddFolderButton widget"""
 
42
 
 
43
    folderCreated = QtCore.pyqtSignal(unicode)
 
44
    folderCreationCanceled = QtCore.pyqtSignal()
 
45
 
 
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__)
 
53
 
 
54
    @QtCore.pyqtSlot()
 
55
    @defer.inlineCallbacks
 
56
    def on_clicked(self):
 
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)
 
62
        if folder == '':
 
63
            self.folderCreationCanceled.emit()
 
64
            return
 
65
 
 
66
        is_valid = yield self.backend.validate_path_for_folder(folder)
 
67
        if not is_valid:
 
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)
 
72
            return
 
73
 
 
74
        yield self.backend.create_folder(folder_path=folder)
 
75
        self.folderCreated.emit(folder)