2016-12-29 12:57:27 -05:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
"""
|
|
|
|
OnionShare | https://onionshare.org/
|
|
|
|
|
2018-04-24 13:07:59 -04:00
|
|
|
Copyright (C) 2014-2018 Micah Lee <micah@micahflee.com>
|
2016-12-29 12:57:27 -05: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/>.
|
|
|
|
"""
|
|
|
|
from PyQt5 import QtCore, QtWidgets, QtGui
|
|
|
|
|
2019-10-13 00:01:25 -04:00
|
|
|
|
2016-12-29 12:57:27 -05:00
|
|
|
class Alert(QtWidgets.QMessageBox):
|
|
|
|
"""
|
|
|
|
An alert box dialog.
|
|
|
|
"""
|
2019-10-13 00:01:25 -04:00
|
|
|
|
|
|
|
def __init__(
|
|
|
|
self,
|
|
|
|
common,
|
|
|
|
message,
|
|
|
|
icon=QtWidgets.QMessageBox.NoIcon,
|
|
|
|
buttons=QtWidgets.QMessageBox.Ok,
|
|
|
|
autostart=True,
|
|
|
|
):
|
2016-12-29 12:57:27 -05:00
|
|
|
super(Alert, self).__init__(None)
|
2018-03-08 13:18:31 -05:00
|
|
|
|
|
|
|
self.common = common
|
|
|
|
|
2019-10-13 00:01:25 -04:00
|
|
|
self.common.log("Alert", "__init__")
|
2017-05-16 14:31:52 -04:00
|
|
|
|
2016-12-29 12:57:27 -05:00
|
|
|
self.setWindowTitle("OnionShare")
|
2019-10-13 00:01:25 -04:00
|
|
|
self.setWindowIcon(
|
|
|
|
QtGui.QIcon(self.common.get_resource_path("images/logo.png"))
|
|
|
|
)
|
2016-12-29 12:57:27 -05:00
|
|
|
self.setText(message)
|
|
|
|
self.setIcon(icon)
|
2017-05-14 22:21:33 -04:00
|
|
|
self.setStandardButtons(buttons)
|
|
|
|
|
|
|
|
if autostart:
|
|
|
|
self.exec_()
|
2018-04-25 11:43:40 -04:00
|
|
|
|
|
|
|
|
|
|
|
class AddFileDialog(QtWidgets.QFileDialog):
|
|
|
|
"""
|
|
|
|
Overridden version of QFileDialog which allows us to select folders as well
|
|
|
|
as, or instead of, files. For adding files/folders to share.
|
2018-11-27 15:10:16 -05:00
|
|
|
|
|
|
|
Note that this dialog can't be used in macOS, only in Windows, Linux, and BSD.
|
|
|
|
This is because the macOS sandbox requires native dialogs, and this is a Qt5
|
|
|
|
dialog.
|
2018-04-25 11:43:40 -04:00
|
|
|
"""
|
2019-10-13 00:01:25 -04:00
|
|
|
|
2018-04-25 11:43:40 -04:00
|
|
|
def __init__(self, common, *args, **kwargs):
|
|
|
|
QtWidgets.QFileDialog.__init__(self, *args, **kwargs)
|
|
|
|
|
|
|
|
self.common = common
|
2019-10-13 00:01:25 -04:00
|
|
|
self.common.log("AddFileDialog", "__init__")
|
2018-04-25 11:43:40 -04:00
|
|
|
|
|
|
|
self.setOption(self.DontUseNativeDialog, True)
|
|
|
|
self.setOption(self.ReadOnly, True)
|
|
|
|
self.setOption(self.ShowDirsOnly, False)
|
|
|
|
self.setFileMode(self.ExistingFiles)
|
|
|
|
tree_view = self.findChild(QtWidgets.QTreeView)
|
|
|
|
tree_view.setSelectionMode(QtWidgets.QAbstractItemView.ExtendedSelection)
|
|
|
|
list_view = self.findChild(QtWidgets.QListView, "listView")
|
|
|
|
list_view.setSelectionMode(QtWidgets.QAbstractItemView.ExtendedSelection)
|
|
|
|
|
|
|
|
def accept(self):
|
2019-10-13 00:01:25 -04:00
|
|
|
self.common.log("AddFileDialog", "accept")
|
2018-04-25 11:43:40 -04:00
|
|
|
QtWidgets.QDialog.accept(self)
|
2019-11-02 21:29:24 -04:00
|
|
|
|
|
|
|
|
|
|
|
class MinimumWidthWidget(QtWidgets.QWidget):
|
|
|
|
"""
|
|
|
|
An empty widget with a minimum width, just to force layouts to behave
|
|
|
|
"""
|
|
|
|
|
|
|
|
def __init__(self, width):
|
|
|
|
super(MinimumWidthWidget, self).__init__()
|
|
|
|
self.setMinimumWidth(width)
|
|
|
|
|