mirror of
https://github.com/onionshare/onionshare.git
synced 2024-12-28 16:59:35 -05:00
Make ShareMode and ReceiveMode inherit from the same class, Mode
This commit is contained in:
parent
df346ad0ab
commit
691db6343d
67
onionshare_gui/mode.py
Normal file
67
onionshare_gui/mode.py
Normal file
@ -0,0 +1,67 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
"""
|
||||||
|
OnionShare | https://onionshare.org/
|
||||||
|
|
||||||
|
Copyright (C) 2014-2018 Micah Lee <micah@micahflee.com>
|
||||||
|
|
||||||
|
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
|
||||||
|
|
||||||
|
from onionshare import strings
|
||||||
|
|
||||||
|
from .server_status import ServerStatus
|
||||||
|
|
||||||
|
class Mode(QtWidgets.QWidget):
|
||||||
|
"""
|
||||||
|
The class that ShareMode and ReceiveMode inherit from.
|
||||||
|
"""
|
||||||
|
def __init__(self, common, qtapp, app, web, status_bar, server_share_status_label, system_tray, filenames=None):
|
||||||
|
super(Mode, self).__init__()
|
||||||
|
self.common = common
|
||||||
|
self.qtapp = qtapp
|
||||||
|
self.app = app
|
||||||
|
self.web = web
|
||||||
|
|
||||||
|
self.status_bar = status_bar
|
||||||
|
self.server_share_status_label = server_share_status_label
|
||||||
|
self.system_tray = system_tray
|
||||||
|
|
||||||
|
self.filenames = filenames
|
||||||
|
|
||||||
|
# Server status
|
||||||
|
self.server_status = ServerStatus(self.common, self.qtapp, self.app, self.web, False)
|
||||||
|
|
||||||
|
# Primary action layout
|
||||||
|
self.primary_action_layout = QtWidgets.QVBoxLayout()
|
||||||
|
self.primary_action_layout.addWidget(self.server_status)
|
||||||
|
self.primary_action = QtWidgets.QWidget()
|
||||||
|
self.primary_action.setLayout(self.primary_action_layout)
|
||||||
|
|
||||||
|
# Layout
|
||||||
|
self.layout = QtWidgets.QVBoxLayout()
|
||||||
|
self.layout.addWidget(self.primary_action)
|
||||||
|
self.setLayout(self.layout)
|
||||||
|
|
||||||
|
def init(self):
|
||||||
|
"""
|
||||||
|
Add custom initialization of the mode here.
|
||||||
|
"""
|
||||||
|
pass
|
||||||
|
|
||||||
|
def timer_callback(self):
|
||||||
|
"""
|
||||||
|
This method is called regularly on a timer.
|
||||||
|
"""
|
||||||
|
pass
|
@ -157,7 +157,8 @@ class OnionShareGui(QtWidgets.QMainWindow):
|
|||||||
self.status_bar.insertWidget(0, self.server_share_status_label)
|
self.status_bar.insertWidget(0, self.server_share_status_label)
|
||||||
|
|
||||||
# Share and receive mode widgets
|
# Share and receive mode widgets
|
||||||
self.share_mode = ShareMode(self.common, filenames, qtapp, app, web, self.status_bar, self.server_share_status_label, self.system_tray)
|
self.share_mode = ShareMode(self.common, qtapp, app, web, self.status_bar, self.server_share_status_label, self.system_tray, filenames)
|
||||||
|
self.share_mode.init()
|
||||||
self.share_mode.server_status.server_started.connect(self.update_server_status_indicator)
|
self.share_mode.server_status.server_started.connect(self.update_server_status_indicator)
|
||||||
self.share_mode.server_status.server_stopped.connect(self.update_server_status_indicator)
|
self.share_mode.server_status.server_stopped.connect(self.update_server_status_indicator)
|
||||||
self.share_mode.start_server_finished.connect(self.update_server_status_indicator)
|
self.share_mode.start_server_finished.connect(self.update_server_status_indicator)
|
||||||
@ -169,6 +170,7 @@ class OnionShareGui(QtWidgets.QMainWindow):
|
|||||||
self.share_mode.server_status.hidservauth_copied.connect(self.copy_hidservauth)
|
self.share_mode.server_status.hidservauth_copied.connect(self.copy_hidservauth)
|
||||||
self.share_mode.set_share_server_active.connect(self.set_share_server_active)
|
self.share_mode.set_share_server_active.connect(self.set_share_server_active)
|
||||||
self.receive_mode = ReceiveMode(self.common, qtapp, app, web, self.status_bar, self.server_share_status_label, self.system_tray)
|
self.receive_mode = ReceiveMode(self.common, qtapp, app, web, self.status_bar, self.server_share_status_label, self.system_tray)
|
||||||
|
self.receive_mode.init()
|
||||||
|
|
||||||
self.update_mode_switcher()
|
self.update_mode_switcher()
|
||||||
self.update_server_status_indicator()
|
self.update_server_status_indicator()
|
||||||
|
@ -21,42 +21,23 @@ from PyQt5 import QtCore, QtWidgets, QtGui
|
|||||||
|
|
||||||
from onionshare import strings
|
from onionshare import strings
|
||||||
|
|
||||||
from ..server_status import ServerStatus
|
from ..mode import Mode
|
||||||
|
|
||||||
class ReceiveMode(QtWidgets.QWidget):
|
class ReceiveMode(Mode):
|
||||||
"""
|
"""
|
||||||
Parts of the main window UI for receiving files.
|
Parts of the main window UI for receiving files.
|
||||||
"""
|
"""
|
||||||
def __init__(self, common, qtapp, app, web, status_bar, server_share_status_label, system_tray):
|
def init(self):
|
||||||
super(ReceiveMode, self).__init__()
|
"""
|
||||||
self.common = common
|
Custom initialization for ReceiveMode.
|
||||||
self.qtapp = qtapp
|
"""
|
||||||
self.app = app
|
|
||||||
self.web = web
|
|
||||||
|
|
||||||
self.status_bar = status_bar
|
|
||||||
self.server_share_status_label = server_share_status_label
|
|
||||||
self.system_tray = system_tray
|
|
||||||
|
|
||||||
# Receive mode info
|
# Receive mode info
|
||||||
self.receive_info = QtWidgets.QLabel(strings._('gui_receive_mode_warning', True))
|
self.receive_info = QtWidgets.QLabel(strings._('gui_receive_mode_warning', True))
|
||||||
self.receive_info.setMinimumHeight(80)
|
self.receive_info.setMinimumHeight(80)
|
||||||
self.receive_info.setWordWrap(True)
|
self.receive_info.setWordWrap(True)
|
||||||
|
|
||||||
# Server status
|
|
||||||
self.server_status = ServerStatus(self.common, self.qtapp, self.app, self.web, False)
|
|
||||||
|
|
||||||
# Primary action layout
|
|
||||||
primary_action_layout = QtWidgets.QVBoxLayout()
|
|
||||||
primary_action_layout.addWidget(self.server_status)
|
|
||||||
self.primary_action = QtWidgets.QWidget()
|
|
||||||
self.primary_action.setLayout(primary_action_layout)
|
|
||||||
|
|
||||||
# Layout
|
# Layout
|
||||||
layout = QtWidgets.QVBoxLayout()
|
self.layout.insertWidget(0, self.receive_info)
|
||||||
layout.addWidget(self.receive_info)
|
|
||||||
layout.addWidget(self.primary_action)
|
|
||||||
self.setLayout(layout)
|
|
||||||
|
|
||||||
def timer_callback(self):
|
def timer_callback(self):
|
||||||
"""
|
"""
|
||||||
|
@ -28,12 +28,12 @@ from onionshare.onion import *
|
|||||||
|
|
||||||
from .file_selection import FileSelection
|
from .file_selection import FileSelection
|
||||||
from .downloads import Downloads
|
from .downloads import Downloads
|
||||||
from ..server_status import ServerStatus
|
from ..mode import Mode
|
||||||
from ..onion_thread import OnionThread
|
from ..onion_thread import OnionThread
|
||||||
from ..widgets import Alert
|
from ..widgets import Alert
|
||||||
|
|
||||||
|
|
||||||
class ShareMode(QtWidgets.QWidget):
|
class ShareMode(Mode):
|
||||||
"""
|
"""
|
||||||
Parts of the main window UI for sharing files.
|
Parts of the main window UI for sharing files.
|
||||||
"""
|
"""
|
||||||
@ -44,27 +44,19 @@ class ShareMode(QtWidgets.QWidget):
|
|||||||
starting_server_error = QtCore.pyqtSignal(str)
|
starting_server_error = QtCore.pyqtSignal(str)
|
||||||
set_share_server_active = QtCore.pyqtSignal(bool)
|
set_share_server_active = QtCore.pyqtSignal(bool)
|
||||||
|
|
||||||
def __init__(self, common, filenames, qtapp, app, web, status_bar, server_share_status_label, system_tray):
|
def init(self):
|
||||||
super(ShareMode, self).__init__()
|
"""
|
||||||
self.common = common
|
Custom initialization for ReceiveMode.
|
||||||
self.qtapp = qtapp
|
"""
|
||||||
self.app = app
|
|
||||||
self.web = web
|
|
||||||
|
|
||||||
self.status_bar = status_bar
|
|
||||||
self.server_share_status_label = server_share_status_label
|
|
||||||
self.system_tray = system_tray
|
|
||||||
|
|
||||||
# File selection
|
# File selection
|
||||||
self.file_selection = FileSelection(self.common)
|
self.file_selection = FileSelection(self.common)
|
||||||
if filenames:
|
if self.filenames:
|
||||||
for filename in filenames:
|
for filename in self.filenames:
|
||||||
self.file_selection.file_list.add_file(filename)
|
self.file_selection.file_list.add_file(filename)
|
||||||
|
|
||||||
# Server status
|
# Server status
|
||||||
self.server_status = ServerStatus(self.common, self.qtapp, self.app, self.web, True, self.file_selection)
|
|
||||||
self.server_status.server_started.connect(self.file_selection.server_started)
|
|
||||||
self.server_status.server_started.connect(self.start_server)
|
self.server_status.server_started.connect(self.start_server)
|
||||||
|
self.server_status.server_started.connect(self.file_selection.server_started)
|
||||||
self.server_status.server_stopped.connect(self.file_selection.server_stopped)
|
self.server_status.server_stopped.connect(self.file_selection.server_stopped)
|
||||||
self.server_status.server_stopped.connect(self.stop_server)
|
self.server_status.server_stopped.connect(self.stop_server)
|
||||||
self.server_status.server_stopped.connect(self.update_primary_action)
|
self.server_status.server_stopped.connect(self.update_primary_action)
|
||||||
@ -122,11 +114,7 @@ class ShareMode(QtWidgets.QWidget):
|
|||||||
self.info_widget.hide()
|
self.info_widget.hide()
|
||||||
|
|
||||||
# Primary action layout
|
# Primary action layout
|
||||||
primary_action_layout = QtWidgets.QVBoxLayout()
|
self.primary_action_layout.addWidget(self.filesize_warning)
|
||||||
primary_action_layout.addWidget(self.server_status)
|
|
||||||
primary_action_layout.addWidget(self.filesize_warning)
|
|
||||||
self.primary_action = QtWidgets.QWidget()
|
|
||||||
self.primary_action.setLayout(primary_action_layout)
|
|
||||||
self.primary_action.hide()
|
self.primary_action.hide()
|
||||||
self.update_primary_action()
|
self.update_primary_action()
|
||||||
|
|
||||||
@ -134,11 +122,8 @@ class ShareMode(QtWidgets.QWidget):
|
|||||||
self._zip_progress_bar = None
|
self._zip_progress_bar = None
|
||||||
|
|
||||||
# Layout
|
# Layout
|
||||||
layout = QtWidgets.QVBoxLayout()
|
self.layout.insertWidget(1, self.info_widget)
|
||||||
layout.addWidget(self.info_widget)
|
self.layout.insertLayout(0, self.file_selection)
|
||||||
layout.addLayout(self.file_selection)
|
|
||||||
layout.addWidget(self.primary_action)
|
|
||||||
self.setLayout(layout)
|
|
||||||
|
|
||||||
# Always start with focus on file selection
|
# Always start with focus on file selection
|
||||||
self.file_selection.setFocus()
|
self.file_selection.setFocus()
|
||||||
|
Loading…
Reference in New Issue
Block a user