1
0
mirror of https://github.com/bpozdena/OneDriveGUI.git synced 2026-10-24 04:59:17 +03:00

Merge branch 'dev'

This commit is contained in:
Boris Pozdena
2022-02-10 18:18:13 +01:00
42 changed files with 335 additions and 602 deletions

5
.gitignore vendored
View File

@@ -1,4 +1,7 @@
venv/
.qt_for_python/
OneDriveGUI/__thrash/
src/__thrash/
src/nohup.out
nohup.out
__pycache__/

View File

@@ -1,232 +0,0 @@
import subprocess
import re
import os
from configparser import ConfigParser
from PySide6.QtGui import QPixmap, QIcon
from PySide6.QtCore import Property, Qt
from PySide6.QtWidgets import (
QWizard,
QGridLayout,
QLineEdit,
QWizardPage,
QLabel,
QVBoxLayout,
QComboBox,
QApplication,
QCheckBox,
QPushButton,
)
from OneDriveGUI import read_config
class SetupWizard(QWizard):
def __init__(self, parent=None):
super(SetupWizard, self).__init__(parent)
self.setWindowIcon(QIcon("resources/images/icons8-clouds-48.png"))
self.setPage(1, WizardPage_welcome(self))
self.setPage(2, wizardPage_version_check(self))
self.setPage(3, wizardPage_create_import(self))
self.setPage(4, wizardPage_import(self))
self.setWindowTitle("OneDriveGUI Setup Wizard")
self.resize(640, 480)
self.currentIdChanged.connect(self.on_page_change)
def on_page_change(self):
if self.currentId() == 2:
print("Checking installed OneDrive version")
self.page(2).check_onedrive_version()
class WizardPage_welcome(QWizardPage):
def __init__(self, parent=None):
super(WizardPage_welcome, self).__init__(parent)
self.setTitle("Welcome to OneDriveGUI")
# self.setSubTitle("SubTitle")
# self.label1 = QLabel()
# self.label1.setText("Welcome to OneDriveGUI")
self.label_2 = QLabel()
self.label_2.setText("This wizard will help you with initial OneDrive profile creation/import.")
layout = QVBoxLayout()
# layout.addWidget(self.label1)
layout.addWidget(self.label_2)
self.setLayout(layout)
class wizardPage_version_check(QWizardPage):
def __init__(self, parent=None):
super(wizardPage_version_check, self).__init__(parent)
self.setTitle("OneDrive version check")
# self.label_3 = QLabel()
# self.label_3.setText("Installed OneDrive version:")
self.label_4 = QLabel()
self.label_4.setText("Installed/Not Installed/ version")
self.label_5 = QLabel()
self.label_5.setWordWrap(True)
self.label_5.setText(
"OneDrive Client for Linux does not seem to be installed. Please install it by following " \
"<a href='https://github.com/abraunegg/onedrive/blob/master/docs/INSTALL.md'>instructions</a> for your distro. "
)
layout = QVBoxLayout()
# layout.addWidget(self.label_3)
layout.addWidget(self.label_4)
layout.addWidget(self.label_5)
self.setLayout(layout)
def check_onedrive_version(self):
# Check if OneDrive is installed
od_version_check = subprocess.check_output(["onedrive", "--version"])
if "onedrive v" in str(od_version_check):
self.od_version = re.search(r".\s(v[0-9.]+)", str(od_version_check)).group(1)
print(f"OneDrive {self.od_version} detected.")
self.label_4.setText(f"OneDrive {self.od_version} detected.")
self.label_5.hide()
return True
else:
self.label_4.setText("OneDrive not detected.")
return False
class wizardPage_create_import(QWizardPage):
def __init__(self, parent=None):
super(wizardPage_create_import, self).__init__(parent)
self.setTitle("Create/Import OneDrive profile")
self.checkBox_create = QCheckBox()
self.checkBox_create.setText("Create new OneDrive profile")
self.checkBox_create.stateChanged.connect(self.on_checkbox_change)
self.checkBox_import = QCheckBox()
self.checkBox_import.setText("Import existing OneDrive profile/config")
self.checkBox_import.stateChanged.connect(self.on_checkbox_change)
layout = QVBoxLayout()
layout.addWidget(self.checkBox_create)
layout.addWidget(self.checkBox_import)
self.setLayout(layout)
def on_checkbox_change(self):
if self.checkBox_create.isChecked():
print(f"Create new profile is checked")
self.checkBox_import.setDisabled(True)
# self.wizardPage_create_import.completeChanged()
elif self.checkBox_import.isChecked():
print(f"Import profile is checked")
self.checkBox_create.setDisabled(True)
# self.wizardPage_create_import.completeChanged()
else:
print(f"No option is unchecked")
self.checkBox_import.setDisabled(False)
self.checkBox_create.setDisabled(False)
class wizardPage_import(QWizardPage):
def __init__(self, parent=None):
super(wizardPage_import, self).__init__(parent)
self.setTitle("Create/Import OneDrive profile")
self.label_profile_name = QLabel()
self.label_profile_name.setText("Profile name")
self.label_config_path = QLabel()
self.label_config_path.setText("Config fil path")
self.lineEdit_profile_name = QLineEdit()
self.lineEdit_profile_name.setPlaceholderText("E.g. john@live.com")
self.lineEdit_config_path = QLineEdit()
self.lineEdit_config_path.setPlaceholderText("E.g. ~/.config/onedrive/config")
self.pushButton_import = QPushButton()
layout = QVBoxLayout()
layout.addWidget(self.label_profile_name)
layout.addWidget(self.label_config_path)
layout.addWidget(self.lineEdit_profile_name)
layout.addWidget(self.lineEdit_config_path)
layout.addWidget(self.pushButton_import)
self.setLayout(layout)
def import_profile(self):
"""
Imports pre-existing OneDrive profile.
Loads default values firt, then overwrite them with user settings.
This is to handle cases where imported config contains only some properties.
"""
profile_name = self.lineEdit_profile_name.text()
config_path = os.path.expanduser(self.lineEdit_config_path.text())
# Load all default values.
_default_od_config = read_config("resources/default_config")
default_od_config = _default_od_config._sections
# Load user's settings.
_new_od_config = read_config(config_path)
new_od_config = _new_od_config._sections
# Construct dict with user profile settings.
new_profile = {profile_name: {"config_file": config_path, "enable_debug": False, "mode": "monitor"}}
# Load existing user profiles and add the new profile.
_profiles = ConfigParser()
_profiles.read(PROFILES_FILE)
_profiles[profile_name] = new_profile[profile_name]
# Create profile config file if it does not exist.
profiles_dir = re.search(r"(.+)/profiles$", PROFILES_FILE).group(1)
if not os.path.exists(profiles_dir):
os.makedirs(profiles_dir)
# Save the new profile.
with open(PROFILES_FILE, "w") as configfile:
_profiles.write(configfile)
# Append OD config
new_profile[profile_name].update(default_od_config)
new_profile[profile_name].update(new_od_config)
# Append new profile into running global profile
global_config.update(new_profile)
# print(new_profile)
# print(global_config)
self.settings_window.listWidget_profiles.addItem(profile_name)
self.setting_page = ProfileSettingsPage(profile_name)
self.settings_window.stackedLayout.addWidget(self.setting_page)
# Add status page widget for new profile
main_window.comboBox.addItem(profile_name)
main_window.profile_status_pages[profile_name] = ProfileStatusPage(profile_name)
main_window.stackedLayout.addWidget(main_window.profile_status_pages[profile_name])
# Hide "Create profile" push button from main windows.
main_window.pushButton_new_profile.hide()
print(f"Account {profile_name} has been imported")
self.pushButton_import.setText("Done")
self.pushButton_import.setDisabled(True)

View File

@@ -1,150 +0,0 @@
# -*- coding: utf-8 -*-
################################################################################
## Form generated from reading UI file 'setup_wizard.ui'
##
## Created by: Qt User Interface Compiler version 6.2.2
##
## WARNING! All changes made in this file will be lost when recompiling UI file!
################################################################################
from PySide6.QtCore import (QCoreApplication, QDate, QDateTime, QLocale,
QMetaObject, QObject, QPoint, QRect,
QSize, QTime, QUrl, Qt)
from PySide6.QtGui import (QBrush, QColor, QConicalGradient, QCursor,
QFont, QFontDatabase, QGradient, QIcon,
QImage, QKeySequence, QLinearGradient, QPainter,
QPalette, QPixmap, QRadialGradient, QTransform)
from PySide6.QtWidgets import (QApplication, QCheckBox, QLabel, QLineEdit,
QPushButton, QSizePolicy, QWidget, QWizard,
QWizardPage)
class Ui_SetupWizard(object):
def setupUi(self, SetupWizard):
if not SetupWizard.objectName():
SetupWizard.setObjectName(u"SetupWizard")
SetupWizard.resize(640, 480)
SetupWizard.setMinimumSize(QSize(640, 480))
SetupWizard.setMaximumSize(QSize(640, 480))
SetupWizard.setWizardStyle(QWizard.ClassicStyle)
self.wizardPage_welcome = QWizardPage()
self.wizardPage_welcome.setObjectName(u"wizardPage_welcome")
self.label = QLabel(self.wizardPage_welcome)
self.label.setObjectName(u"label")
self.label.setGeometry(QRect(230, 80, 271, 18))
self.label_2 = QLabel(self.wizardPage_welcome)
self.label_2.setObjectName(u"label_2")
self.label_2.setGeometry(QRect(110, 200, 441, 20))
SetupWizard.setPage(1, self.wizardPage_welcome)
self.wizardPage_version_check = QWizardPage()
self.wizardPage_version_check.setObjectName(u"wizardPage_version_check")
self.label_3 = QLabel(self.wizardPage_version_check)
self.label_3.setObjectName(u"label_3")
self.label_3.setGeometry(QRect(20, 80, 171, 18))
self.label_4 = QLabel(self.wizardPage_version_check)
self.label_4.setObjectName(u"label_4")
self.label_4.setGeometry(QRect(200, 80, 211, 18))
self.label_5 = QLabel(self.wizardPage_version_check)
self.label_5.setObjectName(u"label_5")
self.label_5.setGeometry(QRect(10, 160, 531, 111))
SetupWizard.setPage(2, self.wizardPage_version_check)
self.wizardPage_create_import = QWizardPage()
self.wizardPage_create_import.setObjectName(u"wizardPage_create_import")
self.label_6 = QLabel(self.wizardPage_create_import)
self.label_6.setObjectName(u"label_6")
self.label_6.setGeometry(QRect(30, 70, 481, 18))
self.checkBox_create = QCheckBox(self.wizardPage_create_import)
self.checkBox_create.setObjectName(u"checkBox_create")
self.checkBox_create.setGeometry(QRect(30, 140, 171, 22))
self.checkBox_import = QCheckBox(self.wizardPage_create_import)
self.checkBox_import.setObjectName(u"checkBox_import")
self.checkBox_import.setGeometry(QRect(30, 180, 251, 22))
SetupWizard.setPage(3, self.wizardPage_create_import)
self.wizardPage_import = QWizardPage()
self.wizardPage_import.setObjectName(u"wizardPage_import")
self.label_7 = QLabel(self.wizardPage_import)
self.label_7.setObjectName(u"label_7")
self.label_7.setGeometry(QRect(30, 60, 291, 18))
self.label_profile_name = QLabel(self.wizardPage_import)
self.label_profile_name.setObjectName(u"label_profile_name")
self.label_profile_name.setGeometry(QRect(7, 166, 107, 32))
#if QT_CONFIG(tooltip)
self.label_profile_name.setToolTip(u"")
#endif // QT_CONFIG(tooltip)
self.label_profile_name.setAlignment(Qt.AlignRight|Qt.AlignTrailing|Qt.AlignVCenter)
self.label_config_path = QLabel(self.wizardPage_import)
self.label_config_path.setObjectName(u"label_config_path")
self.label_config_path.setGeometry(QRect(7, 210, 107, 32))
#if QT_CONFIG(tooltip)
self.label_config_path.setToolTip(u"")
#endif // QT_CONFIG(tooltip)
self.label_config_path.setAlignment(Qt.AlignRight|Qt.AlignTrailing|Qt.AlignVCenter)
self.lineEdit_profile_name = QLineEdit(self.wizardPage_import)
self.lineEdit_profile_name.setObjectName(u"lineEdit_profile_name")
self.lineEdit_profile_name.setGeometry(QRect(120, 166, 308, 32))
self.lineEdit_config_path = QLineEdit(self.wizardPage_import)
self.lineEdit_config_path.setObjectName(u"lineEdit_config_path")
self.lineEdit_config_path.setGeometry(QRect(120, 210, 308, 32))
self.pushButton_import = QPushButton(self.wizardPage_import)
self.pushButton_import.setObjectName(u"pushButton_import")
self.pushButton_import.setGeometry(QRect(120, 310, 391, 34))
SetupWizard.setPage(4, self.wizardPage_import)
self.wizardPage_create = QWizardPage()
self.wizardPage_create.setObjectName(u"wizardPage_create")
self.label_10 = QLabel(self.wizardPage_create)
self.label_10.setObjectName(u"label_10")
self.label_10.setGeometry(QRect(40, 70, 231, 18))
self.lineEdit_sync_dir = QLineEdit(self.wizardPage_create)
self.lineEdit_sync_dir.setObjectName(u"lineEdit_sync_dir")
self.lineEdit_sync_dir.setGeometry(QRect(145, 219, 249, 32))
self.lineEdit_new_profile_name = QLineEdit(self.wizardPage_create)
self.lineEdit_new_profile_name.setObjectName(u"lineEdit_new_profile_name")
self.lineEdit_new_profile_name.setGeometry(QRect(145, 180, 249, 32))
self.label_new_profile_name = QLabel(self.wizardPage_create)
self.label_new_profile_name.setObjectName(u"label_new_profile_name")
self.label_new_profile_name.setGeometry(QRect(30, 180, 109, 32))
self.label_sync_dir = QLabel(self.wizardPage_create)
self.label_sync_dir.setObjectName(u"label_sync_dir")
self.label_sync_dir.setGeometry(QRect(30, 219, 109, 32))
self.pushButton_create = QPushButton(self.wizardPage_create)
self.pushButton_create.setObjectName(u"pushButton_create")
self.pushButton_create.setGeometry(QRect(170, 340, 351, 34))
SetupWizard.setPage(5, self.wizardPage_create)
self.wizardPage_finish = QWizardPage()
self.wizardPage_finish.setObjectName(u"wizardPage_finish")
self.label_13 = QLabel(self.wizardPage_finish)
self.label_13.setObjectName(u"label_13")
self.label_13.setGeometry(QRect(20, 80, 591, 171))
self.label_13.setWordWrap(True)
SetupWizard.setPage(6, self.wizardPage_finish)
self.retranslateUi(SetupWizard)
QMetaObject.connectSlotsByName(SetupWizard)
# setupUi
def retranslateUi(self, SetupWizard):
SetupWizard.setWindowTitle(QCoreApplication.translate("SetupWizard", u"Wizard", None))
self.label.setText(QCoreApplication.translate("SetupWizard", u"Welcome to OneDriveGUI", None))
self.label_2.setText(QCoreApplication.translate("SetupWizard", u"This wizard will help you with initial OneDrive profile creation/import.", None))
self.label_3.setText(QCoreApplication.translate("SetupWizard", u"Installed OneDrive version:", None))
self.label_4.setText(QCoreApplication.translate("SetupWizard", u"Installed/Not Installed/ version", None))
self.label_5.setText(QCoreApplication.translate("SetupWizard", u"<html><head/><body><p><span style=\" font-family:'Droid Sans Mono','monospace','monospace','Droid Sans Fallback'; font-size:14px; color:#960000;\">OneDrive Client for Linux does not seem to be installed. </span></p><pre style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; line-height:19px; background-color:#272822;\"><span style=\" font-family:'Droid Sans Mono','monospace','monospace','Droid Sans Fallback'; font-size:14px; color:#960000;\">Please install it by following </span><a href=\"https://github.com/abraunegg/onedrive/blob/master/docs/INSTALL.md\"><span style=\" font-family:'Hack'; text-decoration: underline; color:#960000;\">instructions</span></a><span style=\" font-family:'Droid Sans Mono','monospace','monospace','Droid Sans Fallback'; font-size:14px; color:#960000;\"> for your distro. </span></pre></body></html>", None))
self.label_6.setText(QCoreApplication.translate("SetupWizard", u"Would you like to create a new OneDrive profile or import existing one?", None))
self.checkBox_create.setText(QCoreApplication.translate("SetupWizard", u"Create new profile", None))
self.checkBox_import.setText(QCoreApplication.translate("SetupWizard", u"Import existing profile/config. ", None))
self.label_7.setText(QCoreApplication.translate("SetupWizard", u"Import existing profile/config", None))
self.label_profile_name.setText(QCoreApplication.translate("SetupWizard", u"Profile Name", None))
self.label_config_path.setText(QCoreApplication.translate("SetupWizard", u"Path to config file", None))
self.lineEdit_profile_name.setPlaceholderText(QCoreApplication.translate("SetupWizard", u"E.g. john@live.com", None))
self.lineEdit_config_path.setPlaceholderText(QCoreApplication.translate("SetupWizard", u"E.g. ~/.config/onedrive/config", None))
self.pushButton_import.setText(QCoreApplication.translate("SetupWizard", u"Import profile", None))
self.label_10.setText(QCoreApplication.translate("SetupWizard", u"Create new profile", None))
self.lineEdit_sync_dir.setPlaceholderText(QCoreApplication.translate("SetupWizard", u"E.g. ~/OneDrive_john@live.com/", None))
self.lineEdit_new_profile_name.setPlaceholderText(QCoreApplication.translate("SetupWizard", u"E.g. john@live.com", None))
self.label_new_profile_name.setText(QCoreApplication.translate("SetupWizard", u"New profile name", None))
self.label_sync_dir.setText(QCoreApplication.translate("SetupWizard", u"Sync directory", None))
self.pushButton_create.setText(QCoreApplication.translate("SetupWizard", u"Create new profile", None))
self.label_13.setText(QCoreApplication.translate("SetupWizard", u"<html><head/><body><p>Your OneDrive profile has been created. </p><p><br/></p><p>You can adjust advanced profile options if needed. Once you are happy with the profile settings, start sync with OneDrive. You will be automatically presented with a OneDrive login page if you have not logged on previously.</p></body></html>", None))
# retranslateUi

View File

@@ -1,43 +0,0 @@
# -*- coding: utf-8 -*-
################################################################################
## Form generated from reading UI file 'wizardPage_welcome.ui'
##
## Created by: Qt User Interface Compiler version 6.2.2
##
## WARNING! All changes made in this file will be lost when recompiling UI file!
################################################################################
from PySide6.QtCore import (QCoreApplication, QDate, QDateTime, QLocale,
QMetaObject, QObject, QPoint, QRect,
QSize, QTime, QUrl, Qt)
from PySide6.QtGui import (QBrush, QColor, QConicalGradient, QCursor,
QFont, QFontDatabase, QGradient, QIcon,
QImage, QKeySequence, QLinearGradient, QPainter,
QPalette, QPixmap, QRadialGradient, QTransform)
from PySide6.QtWidgets import (QApplication, QLabel, QSizePolicy, QWidget,
QWizardPage)
class Ui_WizardPage(object):
def setupUi(self, WizardPage):
if not WizardPage.objectName():
WizardPage.setObjectName(u"WizardPage")
WizardPage.resize(628, 420)
self.label = QLabel(WizardPage)
self.label.setObjectName(u"label")
self.label.setGeometry(QRect(230, 160, 271, 18))
self.label_2 = QLabel(WizardPage)
self.label_2.setObjectName(u"label_2")
self.label_2.setGeometry(QRect(110, 280, 441, 20))
self.retranslateUi(WizardPage)
QMetaObject.connectSlotsByName(WizardPage)
# setupUi
def retranslateUi(self, WizardPage):
WizardPage.setWindowTitle(QCoreApplication.translate("WizardPage", u"WizardPage", None))
self.label.setText(QCoreApplication.translate("WizardPage", u"Welcome to OneDriveGUI", None))
self.label_2.setText(QCoreApplication.translate("WizardPage", u"This wizard will help you with initial OneDrive profile creation/import.", None))
# retranslateUi

View File

@@ -1,45 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>WizardPage</class>
<widget class="QWizardPage" name="WizardPage">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>628</width>
<height>420</height>
</rect>
</property>
<property name="windowTitle">
<string>WizardPage</string>
</property>
<widget class="QLabel" name="label">
<property name="geometry">
<rect>
<x>230</x>
<y>160</y>
<width>271</width>
<height>18</height>
</rect>
</property>
<property name="text">
<string>Welcome to OneDriveGUI</string>
</property>
</widget>
<widget class="QLabel" name="label_2">
<property name="geometry">
<rect>
<x>110</x>
<y>280</y>
<width>441</width>
<height>20</height>
</rect>
</property>
<property name="text">
<string>This wizard will help you with initial OneDrive profile creation/import.</string>
</property>
</widget>
</widget>
<resources/>
<connections/>
</ui>

View File

@@ -1 +1,41 @@
# OneDriveGUI
# OneDriveGUI
A simple GUI for [abraunegg's OneDrive Linux client](https://github.com/abraunegg/onedrive) , with multi-account support.
# Usecases
- Create new OneDrive profile or import pre-existing one.
- Perform configuration changes.
- Start/Stop OneDrive monitoring mode.
- Real-time file transfer monitoring (monitor-mode only).
# Important notes
- This project is currently in alpha stage.
- Check for known [issues/limitations](https://github.com/bpozdena/OneDriveGUI/issues).
- Suggetions and bug reports are welcome.
# Installation steps
1) Ensure [OneDrive for Linux](https://abraunegg.github.io/) is instelled based on [instructions](https://github.com/abraunegg/onedrive/blob/master/docs/INSTALL.md) for your distro.
1) Ensure Python3 and [pip](https://pip.pypa.io/en/stable/installation/) are installed on your system.
1) Clone or download content this repository.
1) (Optional) Create and activate a Python virtual environment:
```sh
python -m venv venv
source venv/bin/activate
```
1) Install dependencies:
```sh
python -m pip install -r requirements.txt
```
1) Start OneDrive GUI:
```sh
cd OneDriveGUI/
python OneDriveGUI.py
```
Optionaly, you can detach the GUI from terminal by using the bellow command:
```sh
nohup python OneDriveGUI.py > /dev/null 2>&1&
```

20
docs/INSTALL.md Normal file
View File

@@ -0,0 +1,20 @@
# Installation steps
1) Ensure [OneDrive for Linux](https://abraunegg.github.io/) is installed based on [instructions](https://github.com/abraunegg/onedrive/blob/master/docs/INSTALL.md) for your distro.
1) Ensure Python3 and [pip](https://pip.pypa.io/en/stable/installation/) are installed on your system.
1) Clone or download content this repository.
1) (Optional) Create and activate a Python virtual environment:
```sh
python3 -m venv venv
source venv/bin/activate
```
1) Install dependencies:
```sh
python3 -m pip install -r requirements.txt
```
1) Start OneDrive GUI:
```sh
cd src/
python3 OneDriveGUI.py
```

View File

@@ -1,2 +1 @@
psutil==5.9.0
PySide6==6.2.2.1

10
src/OneDriveGUI.desktop Executable file
View File

@@ -0,0 +1,10 @@
#!/usr/bin/env xdg-open
[Desktop Entry]
Name=OneDriveGUI
Version=v0.2.0
Icon=icons8-clouds-48
X-Icon-Path=/home/bob/OneDrive/Python/OneDriveGUI/src/resources/images/icons8-clouds-48.ico
Exec=python /home/bob/OneDrive/Python/OneDriveGUI/src/OneDriveGUI.py
Terminal=false
Type=Application
StartupNotify=true

View File

@@ -1,13 +1,16 @@
#!/usr/bin/env python3
from optparse import Option
import os
import re
import subprocess
import sys
import logging
import logging.handlers as handlers
from configparser import ConfigParser
from PySide6.QtCore import QThread, QTimer, QUrl, Signal, QFileInfo, Qt, QDir
from PySide6.QtGui import QIcon, QPixmap
from PySide6.QtGui import QIcon, QPixmap, QDesktopServices
from PySide6.QtWidgets import (
QWidget,
QApplication,
@@ -32,7 +35,6 @@ from PySide6.QtWidgets import (
)
# TODO: Split into multiple files once all main features are implemented.
# Import for login window.
from ui.ui_login import Ui_LoginWindow
@@ -55,6 +57,19 @@ from ui.ui_create_new_profile import Ui_create_new_profile
PROFILES_FILE = os.path.expanduser("~/.config/onedrive-gui/profiles")
# Logging
# dir_path = os.path.dirname(os.path.realpath(__file__))
log_path = os.path.expanduser("~/.config/onedrive-gui/onedrivegui.log")
# file_handler = logging.FileHandler(filename=log_path)
timed_handler = handlers.TimedRotatingFileHandler(filename=log_path, when='D', interval=1, backupCount=2)
stdout_handler = logging.StreamHandler(sys.stdout)
handlers = [timed_handler, stdout_handler]
logging.basicConfig(
format="%(asctime)s - %(levelname)s - %(message)s",
handlers=handlers,
level=logging.DEBUG,
)
class SetupWizard(QWizard):
def __init__(self, parent=None):
@@ -77,7 +92,7 @@ class SetupWizard(QWizard):
def on_page_change(self):
if self.currentId() == 2:
print("Checking installed OneDrive version")
logging.info("Checking installed OneDrive version")
self.page(2).check_onedrive_version()
def nextId(self):
@@ -127,9 +142,10 @@ class wizardPage_version_check(QWizardPage):
self.label_4 = QLabel()
self.label_4.setText("Installed/Not Installed/ version")
self.label_5 = QLabel()
self.label_5.setWordWrap(True)
self.label_5.setStyleSheet("color: red;")
self.label_5.setText(
"OneDrive Client for Linux does not seem to be installed. Please install it by following "
"<a href='https://github.com/abraunegg/onedrive/blob/master/docs/INSTALL.md'>instructions</a> for your distro. "
@@ -143,16 +159,35 @@ class wizardPage_version_check(QWizardPage):
def check_onedrive_version(self):
# Check if OneDrive is installed
od_version_check = subprocess.check_output(["onedrive", "--version"])
if "onedrive v" in str(od_version_check):
self.od_version = re.search(r".\s(v[0-9.]+)", str(od_version_check)).group(1)
print(f"OneDrive {self.od_version} detected.")
self.label_4.setText(f"OneDrive {self.od_version} detected.")
self.label_5.hide()
return True
else:
self.label_4.setText("OneDrive not detected.")
# TODO: Minimim version check not yet enforced
try:
od_version_check = subprocess.check_output(["onedrive", "--version"], stderr=subprocess.STDOUT)
if "onedrive v" in str(od_version_check):
self.od_version = re.search(r".\s(v[0-9.]+)", str(od_version_check)).group(1)
logging.info(f"OneDrive {self.od_version} detected.")
self.label_4.setText(f"OneDrive {self.od_version} detected.")
self.label_4.setStyleSheet("color: green;")
self.label_5.hide()
self.completeChanged.emit()
return True
else:
self.label_4.setText("OneDrive not detected.")
self.label_4.setStyleSheet("color: red;")
self.completeChanged.emit()
return False
except FileNotFoundError:
self.label_4.setText("OneDrive not detected.")
self.label_4.setStyleSheet("color: red;")
self.completeChanged.emit()
return False
def isComplete(self):
if 'not' in self.label_4.text().lower():
return False
else:
return True
class wizardPage_create_import(QWizardPage):
@@ -175,27 +210,27 @@ class wizardPage_create_import(QWizardPage):
def on_checkbox_change(self):
if self.checkBox_create.isChecked():
print(f"Create new profile is checked")
logging.info(f"Create new profile is checked")
self.checkBox_import.setDisabled(True)
self.completeChanged.emit()
elif self.checkBox_import.isChecked():
print(f"Import profile is checked")
logging.info(f"Import profile is checked")
self.checkBox_create.setDisabled(True)
self.completeChanged.emit()
else:
print(f"No option is unchecked")
logging.info(f"No option is unchecked")
self.checkBox_import.setDisabled(False)
self.checkBox_create.setDisabled(False)
self.completeChanged.emit()
def isComplete(self):
if self.checkBox_create.isChecked() == False and self.checkBox_import.isChecked() == False:
print("not complete")
logging.info("not complete")
return False
else:
print("complete")
logging.info("complete")
return True
@@ -248,13 +283,10 @@ class wizardPage_create(QWizardPage):
return False
def get_dir_name(self):
self.file_dialog = QFileDialog.getExistingDirectory(
dir=os.path.expanduser("~/")
) # getOpenFileName(self, dir=os.path.expanduser("~/.config/"))
self.file_dialog = QFileDialog.getExistingDirectory(dir=os.path.expanduser("~/"))
dir_name = self.file_dialog
print(dir_name)
logging.info(dir_name)
self.lineEdit_sync_dir.setText(dir_name)
def update_sync_dir(self, text):
@@ -315,7 +347,7 @@ class wizardPage_create(QWizardPage):
# Hide "Create profile" push button from main windows.
main_window.pushButton_new_profile.hide()
print(f"Account {profile_name} has been created")
logging.info(f"Account {profile_name} has been created")
self.pushButton_create.setText("Done")
self.pushButton_create.setDisabled(True)
self.completeChanged.emit()
@@ -367,7 +399,7 @@ class wizardPage_import(QWizardPage):
file_name = self.file_dialog[0]
print(file_name)
logging.info(file_name)
self.lineEdit_config_path.setText(file_name)
def import_profile(self):
@@ -411,8 +443,8 @@ class wizardPage_import(QWizardPage):
# Append new profile into running global profile
global_config.update(new_profile)
# print(new_profile)
# print(global_config)
# logging.info(new_profile)
# logging.info(global_config)
settings_window.listWidget_profiles.addItem(profile_name)
self.setting_page = ProfileSettingsPage(profile_name)
@@ -426,7 +458,7 @@ class wizardPage_import(QWizardPage):
# Hide "Create profile" push button from main windows.
main_window.pushButton_new_profile.hide()
print(f"Account {profile_name} has been imported")
logging.info(f"Account {profile_name} has been imported")
self.pushButton_import.setText("Done")
self.pushButton_import.setDisabled(True)
self.completeChanged.emit()
@@ -461,21 +493,34 @@ class SettingsWindow(QWidget, Ui_settings_window):
self.stackedLayout = QStackedLayout()
for profile in global_config:
print(profile)
logging.info(profile)
self.listWidget_profiles.addItem(profile)
self.page = ProfileSettingsPage(profile)
self.stackedLayout.addWidget(self.page)
self.horizontalLayout.addLayout(self.stackedLayout)
self.listWidget_profiles.itemSelectionChanged.connect(self.switch_account_settings_page)
self.pushButton_open_create.clicked.connect(self.create_new_profile_window)
self.pushButton_open_create.hide()
self.pushButton_open_import.clicked.connect(self.import_profile_window)
self.pushButton_open_import.hide()
self.pushButton_remove.clicked.connect(self.remove_profile)
self.pushButton_create_import.clicked.connect(self.show_setup_wizard)
self.show()
def closeEvent(self, event):
event.ignore()
self.hide()
def switch_account_settings_page(self):
self.stackedLayout.setCurrentIndex(self.listWidget_profiles.currentRow())
def show_setup_wizard(self):
self.setup_wizard = SetupWizard()
self.setup_wizard.show()
def create_new_profile_window(self):
# Show profile creation window
self.create_window = QWidget()
@@ -515,7 +560,7 @@ class SettingsWindow(QWidget, Ui_settings_window):
main_window.comboBox.removeItem(combo_box_index)
main_window.profile_status_pages.pop(selected_profile_name, None)
global_config.pop(selected_profile_name, None)
print(global_config)
logging.info(global_config)
# Load existing user profiles and remove the new profile.
_profiles = ConfigParser()
@@ -622,8 +667,8 @@ class SettingsWindow(QWidget, Ui_settings_window):
# Append new profile into running global profile
global_config.update(new_profile)
# print(new_profile)
# print(global_config)
# logging.info(new_profile)
# logging.info(global_config)
self.listWidget_profiles.addItem(profile_name)
self.page = ProfileSettingsPage(profile_name)
@@ -646,23 +691,33 @@ class ProfileStatusPage(QWidget, Ui_status_page):
self.toolButton_start.clicked.connect(self.start_monitor)
self.toolButton_stop.clicked.connect(self.stop_monitor)
# Open Sync Dir
self.pushButton_open_dir.clicked.connect(self.open_sync_dir)
# Open Settings window
self.pushButton_settings.clicked.connect(lambda: settings_window.show())
self.pushButton_2.setText("Wizard")
self.pushButton_2.clicked.connect(self.show_setup_wizard)
self.pushButton_2.hide()
def open_sync_dir(self):
sync_dir = global_config[self.profile_name]["onedrive"]["sync_dir"].strip('"')
url = QUrl(os.path.expanduser(sync_dir))
QDesktopServices.openUrl(url)
def show_setup_wizard(self):
self.setup_wizard = SetupWizard()
self.setup_wizard.show()
# self.currentIdChanged.connect(print("print test"))
# self.currentIdChanged.connect(logging.info("print test"))
def stop_monitor(self):
if self.profile_name in main_window.workers:
main_window.workers[self.profile_name].stop_worker()
self.label_onedrive_status.setText("OneDrive sync has been stopped")
logging.info(f"OneDrive sync for profile {self.profile_name} has been stopped.")
else:
print(f"OneDrive for profile {self.profile_name} is not running")
logging.info(f"OneDrive for profile {self.profile_name} is not running.")
def start_monitor(self):
main_window.start_onedrive_monitor(self.profile_name)
@@ -696,6 +751,8 @@ class ProfileSettingsPage(QWidget, Ui_profile_settings):
self.checkBox_sync_root_files.setChecked(self.get_check_box_state("sync_root_files"))
self.checkBox_sync_root_files.stateChanged.connect(self.set_check_box_state)
self.pushButton_sync_dir_browse.clicked.connect(self.get_sync_dir_name)
#
# Excluded files tab
#
@@ -798,7 +855,7 @@ class ProfileSettingsPage(QWidget, Ui_profile_settings):
self.lineEdit_azure_tenant_id.setText(self.temp_profile_config["azure_tenant_id"].strip('"'))
self.lineEdit_azure_tenant_id.textChanged.connect(self.set_line_edit_value)
# Rate limit tab
# Rate limit
self.spinBox_rate_limit.setValue(int(self.temp_profile_config["rate_limit"].strip('"')))
self.horizontalSlider_rate_limit.setValue(int(self.temp_profile_config["rate_limit"].strip('"')))
self.label_rate_limit_mbps.setText(
@@ -846,6 +903,8 @@ class ProfileSettingsPage(QWidget, Ui_profile_settings):
self.lineEdit_log_dir.setText(self.temp_profile_config["log_dir"].strip('"'))
self.lineEdit_log_dir.textChanged.connect(self.set_log_dir)
self.pushButton_log_dir_browse.clicked.connect(self.get_log_dir_name)
self.checkBox_enable_logging.setChecked(self.get_check_box_state("enable_logging"))
self.checkBox_enable_logging.stateChanged.connect(self.set_check_box_state)
@@ -868,8 +927,11 @@ class ProfileSettingsPage(QWidget, Ui_profile_settings):
self.config_dir = re.search(r"(.+)/.+$", self.config_file).group(1)
self.pushButton_login.clicked.connect(lambda: main_window.show_login(self.profile))
self.pushButton_logout.clicked.connect(lambda: os.system(f"onedrive --confdir='{self.config_dir}' --logout"))
self.pushButton_logout.clicked.connect(lambda: print(f"Profile {self.profile} has been logged out."))
self.pushButton_login.hide()
self.pushButton_logout.clicked.connect(self.logout)
# self.pushButton_logout.clicked.connect(lambda: os.system(f"onedrive --confdir='{self.config_dir}' --logout"))
# self.pushButton_logout.clicked.connect(lambda: logging.info(f"Profile {self.profile} has been logged out."))
#
# Buttons
@@ -879,9 +941,41 @@ class ProfileSettingsPage(QWidget, Ui_profile_settings):
# self.pushButton_discart.clicked.connect(self.discart_changes)
self.pushButton_save.clicked.connect(self.save_profile_settings)
def str2bool(self, value):
return value.lower() in "true"
def logout(self):
os.system(f"onedrive --confdir='{self.config_dir}' --logout")
logging.info(f"Profile {self.profile} has been logged out.")
# self.profile_status["status_message"] = "You have been logged out"
main_window.profile_status_pages[self.profile].stop_monitor()
# main_window.profile_status_pages[self.profile]["status_message"] = "You have been logged out"
if self.profile in main_window.workers:
main_window.workers[self.profile].stop_worker()
main_window.profile_status_pages[self.profile].label_onedrive_status.setText("OneDrive sync has been stopped")
logging.info(f"OneDrive sync for profile {self.profile} has been stopped.")
else:
logging.info(f"OneDrive for profile {self.profile} is not running.")
main_window.profile_status_pages[self.profile].label_onedrive_status.setText("You have been logged out")
def get_sync_dir_name(self):
self.file_dialog = QFileDialog.getExistingDirectory(dir=os.path.expanduser("~/"))
sync_dir = self.file_dialog
logging.info(sync_dir)
self.lineEdit_sync_dir.setText(sync_dir)
def get_log_dir_name(self):
self.file_dialog = QFileDialog.getExistingDirectory(dir=os.path.expanduser("~/"))
log_dir = self.file_dialog
logging.info(log_dir)
self.lineEdit_log_dir.setText(log_dir)
def set_line_edit_value(self, value):
_property = self.sender().objectName()
property = re.search(r"lineEdit_(.+)", _property).group(1)
@@ -895,12 +989,12 @@ class ProfileSettingsPage(QWidget, Ui_profile_settings):
def set_check_box_state(self, state):
_property = self.sender().objectName()
property = re.search(r"checkBox_(.+)", _property).group(1)
print(property)
logging.info(property)
if state == Qt.Checked:
print("is checked")
logging.info("is checked")
self.temp_profile_config[f"{property}"] = '"true"'
else:
print("is unchecked")
logging.info("is unchecked")
self.temp_profile_config[f"{property}"] = '"false"'
def get_check_box_state(self, property):
@@ -936,19 +1030,19 @@ class ProfileSettingsPage(QWidget, Ui_profile_settings):
def add_item_to_qlist(self, source_widget, destination_widget, list):
if source_widget.text() == "":
print("Inoring empty value.")
logging.info("Inoring empty value.")
elif source_widget.text() in list:
print("Item already in exemption list.")
logging.info("Item already in exemption list.")
else:
list.append(source_widget.text())
destination_widget.addItem(source_widget.text())
def remove_item_from_qlist(self, qlistwidget_name, list):
for item in qlistwidget_name.selectedItems():
print("Removing: " + item.text())
logging.info("Removing: " + item.text())
# items.remove(item.text())
qlistwidget_name.takeItem(qlistwidget_name.row(item))
print(list)
logging.info(list)
list.remove(item.text())
def save_profile_settings(self):
@@ -1018,28 +1112,28 @@ class WorkerThread(QThread):
def __init__(self, profile):
super(WorkerThread, self).__init__()
print(f"Starting worker for profile {profile}")
logging.info(f"Starting worker for profile {profile}")
self.config_file = global_config[profile]["config_file"]
self.config_folder = re.search(r"(.+)/.+$", self.config_file)
# print(self.config_file)
# logging.info(self.config_file)
self._command = f"onedrive --confdir='{self.config_folder.group(1)}' --monitor -v"
# print(f"command is: {self._command}")
# logging.info(f"command is: {self._command}")
self.profile_name = profile
def stop_worker(self):
print(f"[{self.profile_name}] Waiting for worker to finish...")
logging.info(f"[{self.profile_name}] Waiting for worker to finish...")
while self.onedrive_process.poll() is None:
self.onedrive_process.kill()
# time.sleep(1)
print(f"[{self.profile_name}] Quiting thread")
logging.info(f"[{self.profile_name}] Quiting thread")
self.quit()
self.wait()
print(f"[{self.profile_name}] Removing thread info")
logging.info(f"[{self.profile_name}] Removing thread info")
main_window.workers.pop(self.profile_name, None)
print(f"Remaining running workers: {main_window.workers}")
logging.info(f"Remaining running workers: {main_window.workers}")
def run(self, resync=False):
"""
@@ -1075,8 +1169,8 @@ class WorkerThread(QThread):
if stdout == "":
continue
# print(bytes(stdout, 'utf-8'))
print(f"[{self.profile_name}] " + stdout.strip())
# logging.info(bytes(stdout, 'utf-8'))
logging.info(f"[{self.profile_name}] " + stdout.strip())
if "Authorize this app visiting" in stdout:
self.onedrive_process.kill()
@@ -1092,7 +1186,7 @@ class WorkerThread(QThread):
self.free_space_bytes = re.search(r"([0-9]+)", stdout).group(1)
self.free_space_human = str(humanize_file_size(int(self.free_space_bytes)))
print(f"[{self.profile_name}] Free Space: {self.free_space_human}")
logging.info(f"[{self.profile_name}] Free Space: {self.free_space_human}")
self.profile_status["free_space"] = f"Free Space: {self.free_space_human}"
# self.profile_status["account_type"] = f"{self.account_type.capitalize()} [{self.free_space_human}]"
self.update_profile_status.emit(self.profile_status, self.profile_name)
@@ -1100,7 +1194,7 @@ class WorkerThread(QThread):
elif "Account Type" in stdout:
self.account_type = re.search(r"\s(\w+)$", stdout).group(1)
self.profile_status["account_type"] = self.account_type.capitalize()
print(f"[{self.profile_name}] Account type: {self.account_type}")
logging.info(f"[{self.profile_name}] Account type: {self.account_type}")
self.update_profile_status.emit(self.profile_status, self.profile_name)
elif "Initializing the OneDrive API" in stdout:
@@ -1140,7 +1234,7 @@ class WorkerThread(QThread):
}
# Update file transfer list
print(transfer_progress_new)
logging.info(transfer_progress_new)
self.update_progress_new.emit(transfer_progress_new, self.profile_name)
# Update profile status message.
@@ -1161,7 +1255,7 @@ class WorkerThread(QThread):
"transfer_complete": transfer_complete,
}
print(transfer_progress_new)
logging.info(transfer_progress_new)
self.update_progress_new.emit(transfer_progress_new, self.profile_name)
if transfer_complete:
@@ -1179,18 +1273,18 @@ class WorkerThread(QThread):
stderr = self.onedrive_process.stderr.readline()
if stderr != "":
if "command not found" in stderr:
print(
logging.info(
"""Onedrive does not seem to be installed. Please install it as per instruction at
https://github.com/abraunegg/onedrive/blob/master/docs/INSTALL.md """
)
elif "--resync is required" in stderr:
print(str(stderr) + " Starting resync.")
logging.info(str(stderr) + " Starting resync.")
self.trigger_resync.emit()
self.run(resync=True)
else:
print("@ERROR " + stderr)
logging.info("@ERROR " + stderr)
class MainWindow(QMainWindow, Ui_MainWindow):
@@ -1226,7 +1320,7 @@ class MainWindow(QMainWindow, Ui_MainWindow):
self.actionRestart_Service.triggered.connect(lambda: os.system("systemctl --user restart onedrive"))
# Start OneDrive monitoring
self.actionStart_Monitor.triggered.connect(lambda: self.start_onedrive_monitor("boris@pozdena.eu"))
self.actionStart_Monitor.triggered.connect(lambda: self.start_onedrive_monitor(""))
# Stop OneDrive monitoring
self.actionStop_Monitor.triggered.connect(lambda: os.system("pkill onedrive"))
@@ -1236,7 +1330,7 @@ class MainWindow(QMainWindow, Ui_MainWindow):
# self.actionObtain_Sync_Status.triggered.connect(lambda: self.onedrive_sync_status())
# Start second account
self.actionstart.triggered.connect(lambda: self.start_onedrive_monitor("pozdenab"))
self.actionstart.triggered.connect(lambda: self.start_onedrive_monitor(""))
self.comboBox.activated.connect(self.switch_account_status_page)
self.stackedLayout = QStackedLayout()
@@ -1259,14 +1353,15 @@ class MainWindow(QMainWindow, Ui_MainWindow):
actionshow = menu.addAction("Show/Hide")
actionshow.triggered.connect(lambda: self.hide() if self.isVisible() else self.show())
setting_action = menu.addAction("Settings")
# setting_action.triggered.connect(self.show_settings)
setting_action.triggered.connect(self.show_settings_window)
quit_action = menu.addAction("Quit")
quit_action.triggered.connect(sys.exit)
self.tray.activated.connect(lambda: self.hide() if self.isVisible() else self.show())
self.tray.setIcon(icon)
self.tray.setContextMenu(menu)
self.tray.show()
self.tray.setToolTip("This is OneDriveGUI")
self.tray.setToolTip("OneDriveGUI")
else:
self.tray = None
@@ -1276,6 +1371,10 @@ class MainWindow(QMainWindow, Ui_MainWindow):
self.refresh_process_status.timeout.connect(lambda: self.onedrive_process_status())
self.refresh_process_status.start(500)
def closeEvent(self, event):
event.ignore()
self.hide()
def show_setup_wizard(self):
self.setup_wizard = SetupWizard()
self.setup_wizard.show()
@@ -1289,22 +1388,22 @@ class MainWindow(QMainWindow, Ui_MainWindow):
def onedrive_process_status(self):
# Check OneDrive status
# print(self.workers)
# logging.info(self.workers)
pixmap_running = QPixmap("resources/images/icons8-green-circle-48.png").scaled(20, 20, Qt.KeepAspectRatio)
pixmap_stopped = QPixmap("resources/images/icons8-red-circle-48.png").scaled(20, 20, Qt.KeepAspectRatio)
for profile_name in global_config:
# print(profile_name)
# logging.info(profile_name)
if profile_name not in self.workers:
self.profile_status_pages[profile_name].label_status.setText("stopped")
self.profile_status_pages[profile_name].label_status.setPixmap(pixmap_stopped)
# print(f"not running {profile_name}")
# logging.info(f"not running {profile_name}")
else:
if self.workers[profile_name].isRunning():
self.profile_status_pages[profile_name].label_status.setText("running")
self.profile_status_pages[profile_name].label_status.setPixmap(pixmap_running)
# print(f"running worker {profile_name}")
# logging.info(f"running worker {profile_name}")
# for onedrive_process in psutil.process_iter():
# if onedrive_process.name().lower() == 'onedrive' and onedrive_process.status() != 'zombie':
@@ -1336,8 +1435,8 @@ class MainWindow(QMainWindow, Ui_MainWindow):
self.workers[profile_name] = WorkerThread(profile_name)
self.workers[profile_name].start()
else:
print(f"Worker for profile {profile_name} is already running. Please stop it first.")
print(f"Running workers: {main_window.workers}")
logging.info(f"Worker for profile {profile_name} is already running. Please stop it first.")
logging.info(f"Running workers: {main_window.workers}")
# self.worker = WorkerThread()
# self.worker.start()
@@ -1346,8 +1445,8 @@ class MainWindow(QMainWindow, Ui_MainWindow):
# self.worker.trigger_resync.connect(self.show_login)
self.workers[profile_name].update_progress_new.connect(self.event_update_progress_new)
self.workers[profile_name].update_profile_status.connect(self.event_update_profile_status)
self.workers[profile_name].started.connect(lambda: print(f"started worker {profile_name}"))
self.workers[profile_name].finished.connect(lambda: print(f"finished worker {profile_name}"))
self.workers[profile_name].started.connect(lambda: logging.info(f"started worker {profile_name}"))
self.workers[profile_name].finished.connect(lambda: logging.info(f"finished worker {profile_name}"))
def event_update_profile_status(self, data, profile):
self.profile_status_pages[profile].label_onedrive_status.setText(data["status_message"])
@@ -1367,7 +1466,7 @@ class MainWindow(QMainWindow, Ui_MainWindow):
_sync_dir = os.path.expanduser(global_config[profile]["onedrive"]["sync_dir"].strip('"'))
# profile_status_page = self.profile_status_pages[profile]
print(data)
logging.info(data)
file_path = f"{_sync_dir}" + "/" + data["file_path"]
absolute_path = QFileInfo(file_path).absolutePath().replace(" ", "%20")
parent_dir = re.search(r".+/([^/]+)/.+$", file_path).group(1)
@@ -1381,15 +1480,15 @@ class MainWindow(QMainWindow, Ui_MainWindow):
file_operation = data["file_operation"]
transfer_complete = data["transfer_complete"]
print("absolute path " + absolute_path)
logging.info("absolute path " + absolute_path)
print("parent dir " + parent_dir)
print("progress: " + progress)
print("progress data: " + humanize_file_size(progress_data))
print("file path: " + file_path)
print("file size: " + humanize_file_size(file_size))
print("file name: " + file_name)
print("file path2: " + file_path2)
logging.info("parent dir " + parent_dir)
logging.info("progress: " + progress)
logging.info("progress data: " + humanize_file_size(progress_data))
logging.info("file path: " + file_path)
logging.info("file size: " + humanize_file_size(file_size))
logging.info("file name: " + file_name)
logging.info("file path2: " + file_path2)
# if data['transfer_complete'] == True:
# if int(data['progress']) == 100:
@@ -1400,10 +1499,10 @@ class MainWindow(QMainWindow, Ui_MainWindow):
last_item = self.profile_status_pages[profile].listWidget.item(0)
last_item_widget = self.profile_status_pages[profile].listWidget.itemWidget(last_item)
last_file_name = last_item_widget.get_file_name()
print(f"The last list item's file name is : {last_file_name}")
logging.info(f"The last list item's file name is : {last_file_name}")
if file_name == last_file_name:
print("Deleting last list item")
logging.info("Deleting last list item")
self.profile_status_pages[profile].listWidget.takeItem(0)
myQCustomQWidget = TaskList()
@@ -1440,6 +1539,7 @@ class MainWindow(QMainWindow, Ui_MainWindow):
self.lw = Ui_LoginWindow()
self.lw.setupUi(self.window1)
self.window1.show()
self.window1.setWindowTitle(f"OneDrive login for profile {profile}")
self.config_file = global_config[profile]["config_file"].strip('"')
self.config_dir = re.search(r"(.+)/.+$", self.config_file).group(1)
@@ -1454,22 +1554,33 @@ class MainWindow(QMainWindow, Ui_MainWindow):
self.lw.loginFrame.setUrl(QUrl(url))
# Wait for user to login and obtain response URL
self.lw.loginFrame.urlChanged.connect(
lambda: self.get_response_url(self.lw.loginFrame.url().toString(), self.config_dir, profile)
)
self.lw.loginFrame.urlChanged.connect(lambda:
self.get_response_url(self.lw.loginFrame.url().toString(), self.config_dir, profile))
# self.profile_status_pages[profile].label_onedrive_status.setText("You have been logged in")
def get_response_url(self, response_url, config_dir, profile):
# Get response URL from OneDrive OAuth2
if "nativeclient?code=" in response_url:
print(f'onedrive --confdir="{config_dir}" --auth-response "{response_url}"')
logging.info(f'onedrive --confdir="{config_dir}" --auth-response "{response_url}"')
os.system(f'onedrive --confdir="{config_dir}" --auth-response "{response_url}"')
print("Login performed")
logging.info("Login performed")
self.window1.hide()
main_window.workers[profile].onedrive_process.kill()
main_window.workers[profile].stop_worker()
main_window.profile_status_pages[profile].label_onedrive_status.setText("You have been logged in. Start sync manually.")
# main_window.workers[profile].onedrive_process.kill()
else:
pass
def humanize_file_size(num, suffix="B"):
for unit in ["", "Ki", "Mi", "Gi", "Ti", "Pi", "Ei", "Zi"]:
if abs(num) < 1024.0:
return f"{num:3.1f}{unit}{suffix}"
num /= 1024.0
return f"{num:.1f}Yi{suffix}"
def read_config(config_file):
with open(config_file, "r") as f:
config_string = "[onedrive]\n" + f.read()
@@ -1522,7 +1633,7 @@ def create_global_config():
profiles[profile].update(default_od_config)
profiles[profile].update(od_config)
# print(profiles)
# logging.info(profiles)
return profiles
@@ -1532,10 +1643,10 @@ def save_global_config():
profile_config_file = os.path.expanduser(global_config[profile]["config_file"].strip('"'))
# print(profile_config_file)
# print(global_config)
# print(global_config[profile])
# print(global_config[profile]['onedrive'])
# logging.info(profile_config_file)
# logging.info(global_config)
# logging.info(global_config[profile])
# logging.info(global_config[profile]['onedrive'])
_od_config = {}
_od_config["onedrive"] = global_config[profile]["onedrive"]
@@ -1560,18 +1671,11 @@ def save_global_config():
with open(profile_config_file, "w") as output:
output.writelines(data[1:])
print(f"{profile} config saved")
logging.info(f"{profile} config saved")
print("All configs saved")
logging.info("All configs saved")
def humanize_file_size(num, suffix="B"):
for unit in ["", "Ki", "Mi", "Gi", "Ti", "Pi", "Ei", "Zi"]:
if abs(num) < 1024.0:
return f"{num:3.1f}{unit}{suffix}"
num /= 1024.0
return f"{num:.1f}Yi{suffix}"
if __name__ == "__main__":
global_config = create_global_config()

View File

Before

Width:  |  Height:  |  Size: 9.4 KiB

After

Width:  |  Height:  |  Size: 9.4 KiB

View File

Before

Width:  |  Height:  |  Size: 1.2 KiB

After

Width:  |  Height:  |  Size: 1.2 KiB

View File

Before

Width:  |  Height:  |  Size: 1.2 KiB

After

Width:  |  Height:  |  Size: 1.2 KiB

View File

Before

Width:  |  Height:  |  Size: 1.4 KiB

After

Width:  |  Height:  |  Size: 1.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 100 KiB

View File

Before

Width:  |  Height:  |  Size: 654 B

After

Width:  |  Height:  |  Size: 654 B

View File

Before

Width:  |  Height:  |  Size: 457 B

After

Width:  |  Height:  |  Size: 457 B

View File

Before

Width:  |  Height:  |  Size: 2.2 KiB

After

Width:  |  Height:  |  Size: 2.2 KiB

View File

Before

Width:  |  Height:  |  Size: 580 B

After

Width:  |  Height:  |  Size: 580 B

View File

Before

Width:  |  Height:  |  Size: 2.0 KiB

After

Width:  |  Height:  |  Size: 2.0 KiB

View File

Before

Width:  |  Height:  |  Size: 1.4 KiB

After

Width:  |  Height:  |  Size: 1.4 KiB

View File

Before

Width:  |  Height:  |  Size: 181 B

After

Width:  |  Height:  |  Size: 181 B

View File

@@ -29,7 +29,7 @@
</size>
</property>
<property name="windowTitle">
<string>Form</string>
<string>OneDrive Login</string>
</property>
<layout class="QHBoxLayout" name="horizontalLayout">
<property name="spacing">
@@ -51,7 +51,7 @@
<widget class="QWebEngineView" name="loginFrame">
<property name="url">
<url>
<string>https://www.seznam.cz/</string>
<string>about:blank</string>
</url>
</property>
</widget>

View File

@@ -7,9 +7,21 @@
<x>0</x>
<y>0</y>
<width>420</width>
<height>807</height>
<height>800</height>
</rect>
</property>
<property name="minimumSize">
<size>
<width>420</width>
<height>0</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>420</width>
<height>16777215</height>
</size>
</property>
<property name="windowTitle">
<string>OneDriveGUI</string>
</property>

View File

@@ -154,7 +154,7 @@
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QPushButton" name="pushButton">
<widget class="QPushButton" name="pushButton_open_dir">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Preferred">
<horstretch>0</horstretch>
@@ -162,7 +162,7 @@
</sizepolicy>
</property>
<property name="text">
<string>Open Folder</string>
<string>Open Sync Directory</string>
</property>
</widget>
</item>

View File

@@ -48,7 +48,7 @@
</size>
</property>
<property name="currentIndex">
<number>5</number>
<number>3</number>
</property>
<widget class="QWidget" name="exemptions_tab_2">
<attribute name="title">
@@ -64,7 +64,7 @@
<item row="1" column="0">
<layout class="QGridLayout" name="gridLayout_5">
<item row="0" column="2">
<widget class="QPushButton" name="pushButton_3">
<widget class="QPushButton" name="pushButton_sync_dir_browse">
<property name="text">
<string>Browse</string>
</property>
@@ -608,7 +608,7 @@
<widget class="QLineEdit" name="lineEdit_log_dir"/>
</item>
<item row="1" column="2">
<widget class="QPushButton" name="pushButton_log_dir">
<widget class="QPushButton" name="pushButton_log_dir_browse">
<property name="text">
<string>Browse</string>
</property>

View File

@@ -51,6 +51,13 @@
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="pushButton_create_import">
<property name="text">
<string>Create/Import wizard</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="pushButton_open_create">
<property name="text">

View File

@@ -36,7 +36,7 @@ class Ui_LoginWindow(object):
self.horizontalLayout.setContentsMargins(0, 0, 0, 0)
self.loginFrame = QWebEngineView(LoginWindow)
self.loginFrame.setObjectName(u"loginFrame")
self.loginFrame.setUrl(QUrl(u"http://www.seznam.cz"))
self.loginFrame.setUrl(QUrl(u"about:blank"))
self.horizontalLayout.addWidget(self.loginFrame)
@@ -47,6 +47,6 @@ class Ui_LoginWindow(object):
# setupUi
def retranslateUi(self, LoginWindow):
LoginWindow.setWindowTitle(QCoreApplication.translate("LoginWindow", u"Form", None))
LoginWindow.setWindowTitle(QCoreApplication.translate("LoginWindow", u"OneDrive Login", None))
# retranslateUi

View File

@@ -24,7 +24,9 @@ class Ui_MainWindow(object):
def setupUi(self, MainWindow):
if not MainWindow.objectName():
MainWindow.setObjectName(u"MainWindow")
MainWindow.resize(420, 807)
MainWindow.resize(420, 800)
MainWindow.setMinimumSize(QSize(420, 0))
MainWindow.setMaximumSize(QSize(420, 16777215))
icon = QIcon()
icon.addFile(u"../../../OneDriveGUI_POC_recovered-multi/icons8-clouds-48.png", QSize(), QIcon.Normal, QIcon.Off)
MainWindow.setWindowIcon(icon)

View File

@@ -94,15 +94,15 @@ class Ui_status_page(object):
self.horizontalLayout = QHBoxLayout()
self.horizontalLayout.setObjectName(u"horizontalLayout")
self.pushButton = QPushButton(status_page)
self.pushButton.setObjectName(u"pushButton")
self.pushButton_open_dir = QPushButton(status_page)
self.pushButton_open_dir.setObjectName(u"pushButton_open_dir")
sizePolicy = QSizePolicy(QSizePolicy.Minimum, QSizePolicy.Preferred)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(self.pushButton.sizePolicy().hasHeightForWidth())
self.pushButton.setSizePolicy(sizePolicy)
sizePolicy.setHeightForWidth(self.pushButton_open_dir.sizePolicy().hasHeightForWidth())
self.pushButton_open_dir.setSizePolicy(sizePolicy)
self.horizontalLayout.addWidget(self.pushButton)
self.horizontalLayout.addWidget(self.pushButton_open_dir)
self.pushButton_2 = QPushButton(status_page)
self.pushButton_2.setObjectName(u"pushButton_2")
@@ -135,7 +135,7 @@ class Ui_status_page(object):
self.toolButton_stop.setText(QCoreApplication.translate("status_page", u"Stop", None))
self.label_account_type.setText("")
self.label_free_space.setText("")
self.pushButton.setText(QCoreApplication.translate("status_page", u"Open Folder", None))
self.pushButton_open_dir.setText(QCoreApplication.translate("status_page", u"Open Sync Directory", None))
self.pushButton_2.setText(QCoreApplication.translate("status_page", u"Sync", None))
self.pushButton_settings.setText(QCoreApplication.translate("status_page", u"Settings", None))
# retranslateUi

View File

@@ -54,10 +54,10 @@ class Ui_profile_settings(object):
self.gridLayout_9.setObjectName(u"gridLayout_9")
self.gridLayout_5 = QGridLayout()
self.gridLayout_5.setObjectName(u"gridLayout_5")
self.pushButton_3 = QPushButton(self.groupBox_8)
self.pushButton_3.setObjectName(u"pushButton_3")
self.pushButton_sync_dir_browse = QPushButton(self.groupBox_8)
self.pushButton_sync_dir_browse.setObjectName(u"pushButton_sync_dir_browse")
self.gridLayout_5.addWidget(self.pushButton_3, 0, 2, 1, 1)
self.gridLayout_5.addWidget(self.pushButton_sync_dir_browse, 0, 2, 1, 1)
self.label_sync_dir = QLabel(self.groupBox_8)
self.label_sync_dir.setObjectName(u"label_sync_dir")
@@ -453,10 +453,10 @@ class Ui_profile_settings(object):
self.gridLayout_8.addWidget(self.lineEdit_log_dir, 1, 1, 1, 1)
self.pushButton_log_dir = QPushButton(self.groupBox_7)
self.pushButton_log_dir.setObjectName(u"pushButton_log_dir")
self.pushButton_log_dir_browse = QPushButton(self.groupBox_7)
self.pushButton_log_dir_browse.setObjectName(u"pushButton_log_dir_browse")
self.gridLayout_8.addWidget(self.pushButton_log_dir, 1, 2, 1, 1)
self.gridLayout_8.addWidget(self.pushButton_log_dir_browse, 1, 2, 1, 1)
self.label_monitor_log_frequency = QLabel(self.groupBox_7)
self.label_monitor_log_frequency.setObjectName(u"label_monitor_log_frequency")
@@ -610,7 +610,7 @@ class Ui_profile_settings(object):
self.retranslateUi(profile_settings)
self.tabWidget.setCurrentIndex(5)
self.tabWidget.setCurrentIndex(3)
QMetaObject.connectSlotsByName(profile_settings)
@@ -620,7 +620,7 @@ class Ui_profile_settings(object):
profile_settings.setWindowTitle(QCoreApplication.translate("profile_settings", u"OneDriveGUI - Profile Settings", None))
self.label_profile_name.setText(QCoreApplication.translate("profile_settings", u"Profile name", None))
self.groupBox_8.setTitle(QCoreApplication.translate("profile_settings", u"Monitored directory", None))
self.pushButton_3.setText(QCoreApplication.translate("profile_settings", u"Browse", None))
self.pushButton_sync_dir_browse.setText(QCoreApplication.translate("profile_settings", u"Browse", None))
self.label_sync_dir.setText(QCoreApplication.translate("profile_settings", u"Sync Folder:", None))
self.checkBox_sync_root_files.setText(QCoreApplication.translate("profile_settings", u"Sync root files", None))
self.tabWidget.setTabText(self.tabWidget.indexOf(self.exemptions_tab_2), QCoreApplication.translate("profile_settings", u"Monitored Files", None))
@@ -667,7 +667,7 @@ class Ui_profile_settings(object):
self.checkBox_enable_logging.setText(QCoreApplication.translate("profile_settings", u"Enable Logging", None))
self.label_log_dir.setText(QCoreApplication.translate("profile_settings", u"Log location:", None))
self.checkBox_debug_https.setText(QCoreApplication.translate("profile_settings", u"Debug HTTPS", None))
self.pushButton_log_dir.setText(QCoreApplication.translate("profile_settings", u"Browse", None))
self.pushButton_log_dir_browse.setText(QCoreApplication.translate("profile_settings", u"Browse", None))
self.label_monitor_log_frequency.setText(QCoreApplication.translate("profile_settings", u"Monitor log frequency", None))
self.groupBox_6.setTitle(QCoreApplication.translate("profile_settings", u"Notifications", None))
self.label_min_notify_changes.setText(QCoreApplication.translate("profile_settings", u"Minimum notify changes", None))

View File

@@ -48,6 +48,11 @@ class Ui_settings_window(object):
self.verticalLayout.addWidget(self.pushButton_remove)
self.pushButton_create_import = QPushButton(settings_window)
self.pushButton_create_import.setObjectName(u"pushButton_create_import")
self.verticalLayout.addWidget(self.pushButton_create_import)
self.pushButton_open_create = QPushButton(settings_window)
self.pushButton_open_create.setObjectName(u"pushButton_open_create")
@@ -74,6 +79,7 @@ class Ui_settings_window(object):
settings_window.setWindowTitle(QCoreApplication.translate("settings_window", u"OneDriveGUI - Settings", None))
self.label_profiles.setText(QCoreApplication.translate("settings_window", u"Profiles:", None))
self.pushButton_remove.setText(QCoreApplication.translate("settings_window", u"Remove profile", None))
self.pushButton_create_import.setText(QCoreApplication.translate("settings_window", u"Create/Import wizard", None))
self.pushButton_open_create.setText(QCoreApplication.translate("settings_window", u"Create new profile", None))
self.pushButton_open_import.setText(QCoreApplication.translate("settings_window", u"Import existing profile", None))
# retranslateUi