~ubuntu-branches/ubuntu/quantal/ubuntuone-control-panel/quantal

« back to all changes in this revision

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

  • Committer: Package Import Robot
  • Author(s): Rodney Dawes
  • Date: 2012-08-29 14:55:29 UTC
  • mfrom: (1.1.37)
  • Revision ID: package-import@ubuntu.com-20120829145529-14mpq0u1ql7dx67l
Tags: 3.99.90-0ubuntu1
* New upstream release.
  - Adding functionality to the Share Links Tab.
  - Fixed saving/restoring the speed throttling (LP: #1040899)
  - Other fixes for darwin port.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# -*- coding: utf-8 -*-
 
2
#
 
3
# Copyright 2012 Canonical Ltd.
 
4
#
 
5
# This program is free software: you can redistribute it and/or modify it
 
6
# under the terms of the GNU General Public License version 3, as published
 
7
# by the Free Software Foundation.
 
8
#
 
9
# This program is distributed in the hope that it will be useful, but
 
10
# WITHOUT ANY WARRANTY; without even the implied warranties of
 
11
# MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
 
12
# PURPOSE.  See the GNU General Public License for more details.
 
13
#
 
14
# You should have received a copy of the GNU General Public License along
 
15
# with this program.  If not, see <http://www.gnu.org/licenses/>.
 
16
 
 
17
"""The UI for Share file widget."""
 
18
 
 
19
import os
 
20
 
 
21
from PyQt4 import QtGui, QtCore
 
22
 
 
23
from ubuntuone.controlpanel import cache
 
24
from ubuntuone.controlpanel.gui.qt.share_links_search import (
 
25
    get_system_icon_for_filename,
 
26
)
 
27
from ubuntuone.controlpanel.gui.qt.ui import share_file_ui
 
28
from ubuntuone.controlpanel.logger import setup_logging
 
29
 
 
30
 
 
31
logger = setup_logging('qt.share_file')
 
32
 
 
33
 
 
34
class ShareFileWidget(cache.Cache, QtGui.QWidget):
 
35
    """Widget with the detail information about the shared file."""
 
36
 
 
37
    linkDisabled = QtCore.pyqtSignal()
 
38
 
 
39
    def __init__(self, file_path='', *args, **kwargs):
 
40
        super(ShareFileWidget, self).__init__(*args, **kwargs)
 
41
        self.ui = share_file_ui.Ui_Form()
 
42
        self.ui.setupUi(self)
 
43
        self.file_path = file_path
 
44
 
 
45
        self.ui.lbl_filename.setText(os.path.basename(file_path))
 
46
        self.ui.lbl_path.setText(file_path)
 
47
        icon = get_system_icon_for_filename(os.path.expanduser(file_path))
 
48
        pixmap = icon.pixmap(24)
 
49
        self.ui.lbl_icon.setPixmap(pixmap)
 
50
 
 
51
        self.ui.btn_open.clicked.connect(self.open_file)
 
52
        self.ui.btn_disable.clicked.connect(self.disable_link)
 
53
 
 
54
    def open_file(self):
 
55
        """Open the specified file."""
 
56
        path = u'file://%s' % self.file_path
 
57
        QtGui.QDesktopServices.openUrl(QtCore.QUrl(path))
 
58
 
 
59
    def disable_link(self, val):
 
60
        """Change the access of the file to Not Public."""
 
61
        self.backend.change_public_access(
 
62
            os.path.expanduser(self.file_path), False)
 
63
        self.linkDisabled.emit()