2014-09-02 20:30:01 -04:00
|
|
|
# -*- coding: utf-8 -*-
|
2014-09-02 15:10:42 -04:00
|
|
|
"""
|
|
|
|
OnionShare | https://onionshare.org/
|
|
|
|
|
2018-04-24 13:07:59 -04:00
|
|
|
Copyright (C) 2014-2018 Micah Lee <micah@micahflee.com>
|
2014-09-02 15:10:42 -04:00
|
|
|
|
|
|
|
This program is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
"""
|
2014-08-27 17:21:08 -04:00
|
|
|
import os
|
2016-02-12 18:12:27 -05:00
|
|
|
from PyQt5 import QtCore, QtWidgets, QtGui
|
2014-08-27 17:21:08 -04:00
|
|
|
|
2018-03-08 13:18:31 -05:00
|
|
|
from onionshare import strings
|
2014-08-27 17:21:08 -04:00
|
|
|
|
2018-10-07 17:54:51 -04:00
|
|
|
from ...widgets import Alert, AddFileDialog
|
2018-04-24 20:26:54 -04:00
|
|
|
|
2018-02-04 23:36:34 -05:00
|
|
|
class DropHereLabel(QtWidgets.QLabel):
|
|
|
|
"""
|
|
|
|
When there are no files or folders in the FileList yet, display the
|
|
|
|
'drop files here' message and graphic.
|
|
|
|
"""
|
2018-03-08 13:18:31 -05:00
|
|
|
def __init__(self, common, parent, image=False):
|
2018-02-04 23:36:34 -05:00
|
|
|
self.parent = parent
|
|
|
|
super(DropHereLabel, self).__init__(parent=parent)
|
2018-03-08 13:18:31 -05:00
|
|
|
|
|
|
|
self.common = common
|
|
|
|
|
2018-02-04 23:36:34 -05:00
|
|
|
self.setAcceptDrops(True)
|
|
|
|
self.setAlignment(QtCore.Qt.AlignCenter)
|
|
|
|
|
|
|
|
if image:
|
2018-03-08 13:18:31 -05:00
|
|
|
self.setPixmap(QtGui.QPixmap.fromImage(QtGui.QImage(self.common.get_resource_path('images/logo_transparent.png'))))
|
2018-02-04 23:36:34 -05:00
|
|
|
else:
|
|
|
|
self.setText(strings._('gui_drag_and_drop', True))
|
2018-05-07 19:21:22 -04:00
|
|
|
self.setStyleSheet(self.common.css['share_file_selection_drop_here_label'])
|
2018-02-04 23:36:34 -05:00
|
|
|
|
|
|
|
self.hide()
|
|
|
|
|
|
|
|
def dragEnterEvent(self, event):
|
|
|
|
self.parent.drop_here_image.hide()
|
|
|
|
self.parent.drop_here_text.hide()
|
|
|
|
event.accept()
|
|
|
|
|
|
|
|
|
|
|
|
class DropCountLabel(QtWidgets.QLabel):
|
|
|
|
"""
|
|
|
|
While dragging files over the FileList, this counter displays the
|
|
|
|
number of files you're dragging.
|
|
|
|
"""
|
2018-03-08 13:18:31 -05:00
|
|
|
def __init__(self, common, parent):
|
2018-02-04 23:36:34 -05:00
|
|
|
self.parent = parent
|
|
|
|
super(DropCountLabel, self).__init__(parent=parent)
|
2018-03-08 13:18:31 -05:00
|
|
|
|
|
|
|
self.common = common
|
|
|
|
|
2018-02-04 23:36:34 -05:00
|
|
|
self.setAcceptDrops(True)
|
|
|
|
self.setAlignment(QtCore.Qt.AlignCenter)
|
|
|
|
self.setText(strings._('gui_drag_and_drop', True))
|
2018-05-07 19:21:22 -04:00
|
|
|
self.setStyleSheet(self.common.css['share_file_selection_drop_count_label'])
|
2018-02-04 23:36:34 -05:00
|
|
|
self.hide()
|
|
|
|
|
2018-02-04 23:50:24 -05:00
|
|
|
def dragEnterEvent(self, event):
|
2018-02-04 23:36:34 -05:00
|
|
|
self.hide()
|
|
|
|
event.accept()
|
|
|
|
|
|
|
|
|
2016-02-12 18:12:27 -05:00
|
|
|
class FileList(QtWidgets.QListWidget):
|
2015-11-15 22:01:20 -05:00
|
|
|
"""
|
|
|
|
The list of files and folders in the GUI.
|
|
|
|
"""
|
2014-08-27 17:21:08 -04:00
|
|
|
files_dropped = QtCore.pyqtSignal()
|
2014-08-27 20:24:44 -04:00
|
|
|
files_updated = QtCore.pyqtSignal()
|
2014-08-27 17:21:08 -04:00
|
|
|
|
2018-03-08 13:18:31 -05:00
|
|
|
def __init__(self, common, parent=None):
|
2014-08-27 17:21:08 -04:00
|
|
|
super(FileList, self).__init__(parent)
|
2018-03-08 13:18:31 -05:00
|
|
|
|
|
|
|
self.common = common
|
|
|
|
|
2014-08-27 17:21:08 -04:00
|
|
|
self.setAcceptDrops(True)
|
|
|
|
self.setIconSize(QtCore.QSize(32, 32))
|
2014-08-28 19:26:56 -04:00
|
|
|
self.setSortingEnabled(True)
|
2018-02-18 00:22:04 -05:00
|
|
|
self.setMinimumHeight(205)
|
2018-02-05 00:45:35 -05:00
|
|
|
self.setSelectionMode(QtWidgets.QAbstractItemView.ExtendedSelection)
|
2018-03-08 13:18:31 -05:00
|
|
|
self.drop_here_image = DropHereLabel(self.common, self, True)
|
|
|
|
self.drop_here_text = DropHereLabel(self.common, self, False)
|
|
|
|
self.drop_count = DropCountLabel(self.common, self)
|
2018-02-04 16:13:38 -05:00
|
|
|
self.resizeEvent(None)
|
2018-02-21 22:44:00 -05:00
|
|
|
self.setVerticalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOn)
|
2014-08-27 17:21:08 -04:00
|
|
|
|
|
|
|
def update(self):
|
2015-11-15 22:01:20 -05:00
|
|
|
"""
|
|
|
|
Update the GUI elements based on the current state.
|
|
|
|
"""
|
2014-08-27 17:21:08 -04:00
|
|
|
# file list should have a background image if empty
|
2018-02-20 23:19:18 -05:00
|
|
|
if self.count() == 0:
|
2014-09-17 18:48:19 -04:00
|
|
|
self.drop_here_image.show()
|
|
|
|
self.drop_here_text.show()
|
2014-08-27 17:21:08 -04:00
|
|
|
else:
|
2014-09-17 18:48:19 -04:00
|
|
|
self.drop_here_image.hide()
|
|
|
|
self.drop_here_text.hide()
|
2014-08-27 17:21:08 -04:00
|
|
|
|
2018-02-07 12:16:55 -05:00
|
|
|
def server_started(self):
|
|
|
|
"""
|
|
|
|
Update the GUI when the server starts, by hiding delete buttons.
|
|
|
|
"""
|
|
|
|
self.setAcceptDrops(False)
|
|
|
|
self.setCurrentItem(None)
|
|
|
|
self.setSelectionMode(QtWidgets.QAbstractItemView.NoSelection)
|
|
|
|
for index in range(self.count()):
|
|
|
|
self.item(index).item_button.hide()
|
|
|
|
|
|
|
|
def server_stopped(self):
|
|
|
|
"""
|
|
|
|
Update the GUI when the server stops, by showing delete buttons.
|
|
|
|
"""
|
2018-02-07 12:48:34 -05:00
|
|
|
self.setAcceptDrops(True)
|
2018-02-07 12:16:55 -05:00
|
|
|
self.setSelectionMode(QtWidgets.QAbstractItemView.ExtendedSelection)
|
|
|
|
for index in range(self.count()):
|
|
|
|
self.item(index).item_button.show()
|
|
|
|
|
2014-08-27 17:21:08 -04:00
|
|
|
def resizeEvent(self, event):
|
2015-11-15 22:01:20 -05:00
|
|
|
"""
|
|
|
|
When the widget is resized, resize the drop files image and text.
|
|
|
|
"""
|
2018-02-04 16:13:38 -05:00
|
|
|
offset = 70
|
|
|
|
self.drop_here_image.setGeometry(0, 0, self.width(), self.height() - offset)
|
|
|
|
self.drop_here_text.setGeometry(0, offset, self.width(), self.height() - offset)
|
2014-08-27 17:21:08 -04:00
|
|
|
|
2018-02-04 23:50:24 -05:00
|
|
|
if self.count() > 0:
|
|
|
|
# Add and delete an empty item, to force all items to get redrawn
|
|
|
|
# This is ugly, but the only way I could figure out how to proceed
|
|
|
|
item = QtWidgets.QListWidgetItem('fake item')
|
|
|
|
self.addItem(item)
|
|
|
|
self.takeItem(self.row(item))
|
|
|
|
self.update()
|
2018-02-04 23:09:51 -05:00
|
|
|
|
2018-02-22 18:49:43 -05:00
|
|
|
# Extend any filenames that were truncated to fit the window
|
|
|
|
# We use 200 as a rough guess at how wide the 'file size + delete button' widget is
|
|
|
|
# and extend based on the overall width minus that amount.
|
|
|
|
for index in range(self.count()):
|
|
|
|
metrics = QtGui.QFontMetrics(self.item(index).font())
|
|
|
|
elided = metrics.elidedText(self.item(index).basename, QtCore.Qt.ElideRight, self.width() - 200)
|
|
|
|
self.item(index).setText(elided)
|
|
|
|
|
|
|
|
|
2014-08-27 17:21:08 -04:00
|
|
|
def dragEnterEvent(self, event):
|
2015-11-15 22:01:20 -05:00
|
|
|
"""
|
|
|
|
dragEnterEvent for dragging files and directories into the widget.
|
|
|
|
"""
|
2014-08-27 17:21:08 -04:00
|
|
|
if event.mimeData().hasUrls:
|
2018-05-07 19:21:22 -04:00
|
|
|
self.setStyleSheet(self.common.css['share_file_list_drag_enter'])
|
2018-02-04 22:28:42 -05:00
|
|
|
count = len(event.mimeData().urls())
|
|
|
|
self.drop_count.setText('+{}'.format(count))
|
|
|
|
|
2018-02-10 21:36:38 -05:00
|
|
|
size_hint = self.drop_count.sizeHint()
|
|
|
|
self.drop_count.setGeometry(self.width() - size_hint.width() - 10, self.height() - size_hint.height() - 10, size_hint.width(), size_hint.height())
|
2018-02-04 22:28:42 -05:00
|
|
|
self.drop_count.show()
|
2014-08-27 17:21:08 -04:00
|
|
|
event.accept()
|
|
|
|
else:
|
|
|
|
event.ignore()
|
|
|
|
|
2014-09-17 18:48:19 -04:00
|
|
|
def dragLeaveEvent(self, event):
|
2015-11-15 22:01:20 -05:00
|
|
|
"""
|
|
|
|
dragLeaveEvent for dragging files and directories into the widget.
|
|
|
|
"""
|
2018-05-07 19:21:22 -04:00
|
|
|
self.setStyleSheet(self.common.css['share_file_list_drag_leave'])
|
2018-02-04 22:28:42 -05:00
|
|
|
self.drop_count.hide()
|
2014-09-17 18:48:19 -04:00
|
|
|
event.accept()
|
|
|
|
self.update()
|
|
|
|
|
2014-08-27 17:21:08 -04:00
|
|
|
def dragMoveEvent(self, event):
|
2015-11-15 22:01:20 -05:00
|
|
|
"""
|
|
|
|
dragMoveEvent for dragging files and directories into the widget.
|
|
|
|
"""
|
2014-08-27 17:21:08 -04:00
|
|
|
if event.mimeData().hasUrls:
|
|
|
|
event.setDropAction(QtCore.Qt.CopyAction)
|
|
|
|
event.accept()
|
|
|
|
else:
|
|
|
|
event.ignore()
|
|
|
|
|
|
|
|
def dropEvent(self, event):
|
2015-11-15 22:01:20 -05:00
|
|
|
"""
|
|
|
|
dropEvent for dragging files and directories into the widget.
|
|
|
|
"""
|
2014-08-27 17:21:08 -04:00
|
|
|
if event.mimeData().hasUrls:
|
|
|
|
event.setDropAction(QtCore.Qt.CopyAction)
|
|
|
|
event.accept()
|
|
|
|
for url in event.mimeData().urls():
|
|
|
|
filename = str(url.toLocalFile())
|
|
|
|
self.add_file(filename)
|
|
|
|
else:
|
|
|
|
event.ignore()
|
2018-02-04 22:28:42 -05:00
|
|
|
|
2018-05-07 19:21:22 -04:00
|
|
|
self.setStyleSheet(self.common.css['share_file_list_drag_leave'])
|
2018-02-04 22:28:42 -05:00
|
|
|
self.drop_count.hide()
|
|
|
|
|
2014-08-27 17:21:08 -04:00
|
|
|
self.files_dropped.emit()
|
|
|
|
|
|
|
|
def add_file(self, filename):
|
2015-11-15 22:01:20 -05:00
|
|
|
"""
|
|
|
|
Add a file or directory to this widget.
|
|
|
|
"""
|
2018-02-20 23:47:21 -05:00
|
|
|
filenames = []
|
2018-02-20 23:19:18 -05:00
|
|
|
for index in range(self.count()):
|
2018-02-20 23:29:56 -05:00
|
|
|
filenames.append(self.item(index).filename)
|
2018-02-20 23:19:18 -05:00
|
|
|
|
2018-02-20 23:29:56 -05:00
|
|
|
if filename not in filenames:
|
2017-05-18 13:55:10 -04:00
|
|
|
if not os.access(filename, os.R_OK):
|
2018-03-08 13:18:31 -05:00
|
|
|
Alert(self.common, strings._("not_a_readable_file", True).format(filename))
|
2017-05-18 13:55:10 -04:00
|
|
|
return
|
|
|
|
|
2014-08-27 17:21:08 -04:00
|
|
|
fileinfo = QtCore.QFileInfo(filename)
|
2016-02-12 18:12:27 -05:00
|
|
|
ip = QtWidgets.QFileIconProvider()
|
2014-08-27 17:21:08 -04:00
|
|
|
icon = ip.icon(fileinfo)
|
|
|
|
|
|
|
|
if os.path.isfile(filename):
|
2018-02-10 14:48:14 -05:00
|
|
|
size_bytes = fileinfo.size()
|
2018-03-08 13:18:31 -05:00
|
|
|
size_readable = self.common.human_readable_filesize(size_bytes)
|
2014-08-27 17:21:08 -04:00
|
|
|
else:
|
2018-03-08 13:18:31 -05:00
|
|
|
size_bytes = self.common.dir_size(filename)
|
|
|
|
size_readable = self.common.human_readable_filesize(size_bytes)
|
2018-02-04 23:09:51 -05:00
|
|
|
|
|
|
|
# Create a new item
|
2018-02-10 21:15:44 -05:00
|
|
|
item = QtWidgets.QListWidgetItem()
|
2014-08-27 17:21:08 -04:00
|
|
|
item.setIcon(icon)
|
2018-02-10 14:48:14 -05:00
|
|
|
item.size_bytes = size_bytes
|
2018-02-04 23:09:51 -05:00
|
|
|
|
2018-02-21 22:37:31 -05:00
|
|
|
# Item's filename attribute and size labels
|
2018-02-20 23:19:18 -05:00
|
|
|
item.filename = filename
|
2018-02-10 21:15:44 -05:00
|
|
|
item_size = QtWidgets.QLabel(size_readable)
|
2018-05-07 19:21:22 -04:00
|
|
|
item_size.setStyleSheet(self.common.css['share_file_list_item_size'])
|
2018-02-10 21:15:44 -05:00
|
|
|
|
2018-02-22 18:49:43 -05:00
|
|
|
item.basename = os.path.basename(filename.rstrip('/'))
|
2018-02-20 23:19:18 -05:00
|
|
|
# Use the basename as the method with which to sort the list
|
2018-02-22 18:49:43 -05:00
|
|
|
metrics = QtGui.QFontMetrics(item.font())
|
|
|
|
elided = metrics.elidedText(item.basename, QtCore.Qt.ElideRight, self.sizeHint().width())
|
|
|
|
item.setData(QtCore.Qt.DisplayRole, elided)
|
2018-02-20 23:19:18 -05:00
|
|
|
|
2018-02-05 00:18:41 -05:00
|
|
|
# Item's delete button
|
|
|
|
def delete_item():
|
|
|
|
itemrow = self.row(item)
|
|
|
|
self.takeItem(itemrow)
|
|
|
|
self.files_updated.emit()
|
|
|
|
|
2018-02-07 01:34:36 -05:00
|
|
|
item.item_button = QtWidgets.QPushButton()
|
|
|
|
item.item_button.setDefault(False)
|
|
|
|
item.item_button.setFlat(True)
|
2018-03-08 13:18:31 -05:00
|
|
|
item.item_button.setIcon( QtGui.QIcon(self.common.get_resource_path('images/file_delete.png')) )
|
2018-02-07 01:34:36 -05:00
|
|
|
item.item_button.clicked.connect(delete_item)
|
2018-02-10 21:15:44 -05:00
|
|
|
item.item_button.setSizePolicy(QtWidgets.QSizePolicy.Fixed, QtWidgets.QSizePolicy.Fixed)
|
|
|
|
|
2018-02-22 12:55:04 -05:00
|
|
|
# Item info widget, with a white background
|
|
|
|
item_info_layout = QtWidgets.QHBoxLayout()
|
|
|
|
item_info_layout.addWidget(item_size)
|
|
|
|
item_info_layout.addWidget(item.item_button)
|
|
|
|
item_info = QtWidgets.QWidget()
|
|
|
|
item_info.setObjectName('item-info')
|
|
|
|
item_info.setLayout(item_info_layout)
|
|
|
|
|
2018-02-10 21:15:44 -05:00
|
|
|
# Create the item's widget and layouts
|
|
|
|
item_hlayout = QtWidgets.QHBoxLayout()
|
2018-02-21 22:37:31 -05:00
|
|
|
item_hlayout.addStretch()
|
2018-02-22 12:55:04 -05:00
|
|
|
item_hlayout.addWidget(item_info)
|
2018-02-10 21:15:44 -05:00
|
|
|
widget = QtWidgets.QWidget()
|
|
|
|
widget.setLayout(item_hlayout)
|
2018-02-05 00:18:41 -05:00
|
|
|
|
2018-02-10 21:15:44 -05:00
|
|
|
item.setSizeHint(widget.sizeHint())
|
2018-02-04 23:09:51 -05:00
|
|
|
|
2014-08-27 17:21:08 -04:00
|
|
|
self.addItem(item)
|
2018-02-10 21:15:44 -05:00
|
|
|
self.setItemWidget(item, widget)
|
2014-08-27 17:21:08 -04:00
|
|
|
|
2014-08-27 20:24:44 -04:00
|
|
|
self.files_updated.emit()
|
|
|
|
|
2014-11-18 12:29:32 -05:00
|
|
|
|
2016-02-12 18:12:27 -05:00
|
|
|
class FileSelection(QtWidgets.QVBoxLayout):
|
2015-11-15 22:01:20 -05:00
|
|
|
"""
|
2018-02-05 00:45:35 -05:00
|
|
|
The list of files and folders in the GUI, as well as buttons to add and
|
|
|
|
delete the files and folders.
|
2015-11-15 22:01:20 -05:00
|
|
|
"""
|
2018-03-08 13:18:31 -05:00
|
|
|
def __init__(self, common):
|
2014-08-27 17:21:08 -04:00
|
|
|
super(FileSelection, self).__init__()
|
2018-03-08 13:18:31 -05:00
|
|
|
|
|
|
|
self.common = common
|
|
|
|
|
2014-08-27 20:24:44 -04:00
|
|
|
self.server_on = False
|
2014-08-27 17:21:08 -04:00
|
|
|
|
2018-02-10 14:48:14 -05:00
|
|
|
# File list
|
2018-03-08 13:18:31 -05:00
|
|
|
self.file_list = FileList(self.common)
|
2018-02-23 17:18:57 -05:00
|
|
|
self.file_list.itemSelectionChanged.connect(self.update)
|
2014-08-27 17:21:08 -04:00
|
|
|
self.file_list.files_dropped.connect(self.update)
|
2018-02-10 14:48:14 -05:00
|
|
|
self.file_list.files_updated.connect(self.update)
|
2014-08-27 17:21:08 -04:00
|
|
|
|
2018-02-10 14:48:14 -05:00
|
|
|
# Buttons
|
2017-05-28 20:22:16 -04:00
|
|
|
self.add_button = QtWidgets.QPushButton(strings._('gui_add', True))
|
|
|
|
self.add_button.clicked.connect(self.add)
|
2018-02-05 00:45:35 -05:00
|
|
|
self.delete_button = QtWidgets.QPushButton(strings._('gui_delete', True))
|
|
|
|
self.delete_button.clicked.connect(self.delete)
|
2016-02-12 18:12:27 -05:00
|
|
|
button_layout = QtWidgets.QHBoxLayout()
|
2018-02-05 00:18:41 -05:00
|
|
|
button_layout.addStretch()
|
2017-05-28 20:22:16 -04:00
|
|
|
button_layout.addWidget(self.add_button)
|
2018-02-05 00:45:35 -05:00
|
|
|
button_layout.addWidget(self.delete_button)
|
2014-08-27 17:21:08 -04:00
|
|
|
|
2018-02-10 14:48:14 -05:00
|
|
|
# Add the widgets
|
2014-08-27 17:21:08 -04:00
|
|
|
self.addWidget(self.file_list)
|
|
|
|
self.addLayout(button_layout)
|
|
|
|
|
|
|
|
self.update()
|
|
|
|
|
|
|
|
def update(self):
|
2015-11-15 22:01:20 -05:00
|
|
|
"""
|
|
|
|
Update the GUI elements based on the current state.
|
|
|
|
"""
|
2018-02-05 00:45:35 -05:00
|
|
|
# All buttons should be hidden if the server is on
|
2014-08-27 20:24:44 -04:00
|
|
|
if self.server_on:
|
2018-02-05 00:45:35 -05:00
|
|
|
self.add_button.hide()
|
|
|
|
self.delete_button.hide()
|
2014-08-27 17:21:08 -04:00
|
|
|
else:
|
2018-02-05 00:45:35 -05:00
|
|
|
self.add_button.show()
|
2014-08-27 20:24:44 -04:00
|
|
|
|
2018-02-05 00:45:35 -05:00
|
|
|
# Delete button should be hidden if item isn't selected
|
2018-02-23 17:18:57 -05:00
|
|
|
if len(self.file_list.selectedItems()) == 0:
|
2018-02-05 00:45:35 -05:00
|
|
|
self.delete_button.hide()
|
|
|
|
else:
|
|
|
|
self.delete_button.show()
|
|
|
|
|
|
|
|
# Update the file list
|
2014-08-27 17:21:08 -04:00
|
|
|
self.file_list.update()
|
|
|
|
|
2017-05-28 20:22:16 -04:00
|
|
|
def add(self):
|
2015-11-15 22:01:20 -05:00
|
|
|
"""
|
2017-05-28 20:22:16 -04:00
|
|
|
Add button clicked.
|
2015-11-15 22:01:20 -05:00
|
|
|
"""
|
2018-04-25 11:43:40 -04:00
|
|
|
file_dialog = AddFileDialog(self.common, caption=strings._('gui_choose_items', True))
|
2017-05-21 02:14:32 -04:00
|
|
|
if file_dialog.exec_() == QtWidgets.QDialog.Accepted:
|
2017-05-28 23:47:05 -04:00
|
|
|
for filename in file_dialog.selectedFiles():
|
|
|
|
self.file_list.add_file(filename)
|
2017-05-21 02:14:32 -04:00
|
|
|
|
2018-02-05 00:45:35 -05:00
|
|
|
self.file_list.setCurrentItem(None)
|
|
|
|
self.update()
|
|
|
|
|
|
|
|
def delete(self):
|
|
|
|
"""
|
|
|
|
Delete button clicked
|
|
|
|
"""
|
|
|
|
selected = self.file_list.selectedItems()
|
|
|
|
for item in selected:
|
|
|
|
itemrow = self.file_list.row(item)
|
|
|
|
self.file_list.takeItem(itemrow)
|
|
|
|
self.file_list.files_updated.emit()
|
2018-02-07 12:16:55 -05:00
|
|
|
|
2018-02-05 00:45:35 -05:00
|
|
|
self.file_list.setCurrentItem(None)
|
2014-08-27 17:21:08 -04:00
|
|
|
self.update()
|
|
|
|
|
2014-08-27 20:24:44 -04:00
|
|
|
def server_started(self):
|
2015-11-15 22:01:20 -05:00
|
|
|
"""
|
|
|
|
Gets called when the server starts.
|
|
|
|
"""
|
2014-08-27 20:24:44 -04:00
|
|
|
self.server_on = True
|
2018-02-07 12:16:55 -05:00
|
|
|
self.file_list.server_started()
|
2014-08-27 20:24:44 -04:00
|
|
|
self.update()
|
2014-09-15 20:22:14 -04:00
|
|
|
|
2014-08-27 20:24:44 -04:00
|
|
|
def server_stopped(self):
|
2015-11-15 22:01:20 -05:00
|
|
|
"""
|
|
|
|
Gets called when the server stops.
|
|
|
|
"""
|
2014-08-27 20:24:44 -04:00
|
|
|
self.server_on = False
|
2018-02-07 12:16:55 -05:00
|
|
|
self.file_list.server_stopped()
|
2014-08-27 20:24:44 -04:00
|
|
|
self.update()
|
|
|
|
|
|
|
|
def get_num_files(self):
|
2015-11-15 22:01:20 -05:00
|
|
|
"""
|
|
|
|
Returns the total number of files and folders in the list.
|
|
|
|
"""
|
2018-02-22 20:46:18 -05:00
|
|
|
return len(range(self.file_list.count()))
|
2017-05-16 18:24:14 -04:00
|
|
|
|
|
|
|
def setFocus(self):
|
|
|
|
"""
|
|
|
|
Set the Qt app focus on the file selection box.
|
|
|
|
"""
|
|
|
|
self.file_list.setFocus()
|