Skip to content

Commit

Permalink
Full macOS support, portable more and more
Browse files Browse the repository at this point in the history
  • Loading branch information
TCB13 committed Dec 8, 2021
1 parent 94782d5 commit e5d1292
Show file tree
Hide file tree
Showing 9 changed files with 128 additions and 355 deletions.
16 changes: 11 additions & 5 deletions LoFloccus/LoFloccus.pro
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ FORMS += \
lofloccus.ui

# Generic for all builds
VERSION = 1.2.0
VERSION = 1.2.1
DEFINES += APP_VERSION=\\\"$$VERSION\\\"
INCLUDEPATH += $${PWD}/libs

Expand All @@ -44,6 +44,11 @@ mac {
ICON = assets/icon.icns
QMAKE_TARGET_BUNDLE_PREFIX = "com.tcb13"
LIBS += -L$${PWD}/libs -lLoFloccusDavDarwin

SOURCES += platformdarwin.mm
HEADERS += platformdarwin.h
LIBS += -framework Foundation
LIBS += -framework AppKit
}


Expand All @@ -59,12 +64,13 @@ RESOURCES += \

# Static Builds
QTPREFIX=$$[QT_INSTALL_PREFIX]
equals(QTPREFIX, "C:/Qt-Static/Qt-5.14.2"){
equals(QTPREFIX, "C:/Qt-Static/Qt-5.14.2") || equals(QTPREFIX, "/Users/tcb13/Qt-Static/Qt-5.12.12") {
message("--STATIC BUILD--")
CONFIG += qt static
QMAKE_LFLAGS += -static-libgcc -static-libstdc++
win32 {
QMAKE_LFLAGS += -static-libgcc -static-libstdc++
}

} else {
message("--NON-STATIC BUILD--")
}


264 changes: 10 additions & 254 deletions LoFloccus/LoFloccus.pro.user

Large diffs are not rendered by default.

5 changes: 3 additions & 2 deletions LoFloccus/libs/libLoFloccusDav.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ Complied with:
How to install/compile this as a static library:
1. go get "golang.org/x/net/webdav"
2. Build ir for your architecture:
2.1. Windows: go build -buildmode c-archive -o libLoFloccusDavWin64.a libLoFloccusDav.go
2.2. macOS: go build -buildmode c-shared -o libLoFloccusDavDarwin.a libLoFloccusDav.go
2.1. Windows (dev/release): go build -buildmode c-archive -o libLoFloccusDavWin64.a libLoFloccusDav.go
2.2. macOS (dev): go build -buildmode c-shared -o libLoFloccusDavDarwin.a libLoFloccusDav.go
2.3. macOS (release): go build -buildmode c-archive -o libLoFloccusDavDarwin.a libLoFloccusDav.go
*/

package main
Expand Down
85 changes: 49 additions & 36 deletions LoFloccus/lofloccus.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,16 @@ LoFloccus::LoFloccus(QWidget *parent)
appIcon = QIcon(":/assets/icon.ico");
running = false;

#ifdef Q_OS_DARWIN
darwinBridge = new PlatformDarwin();
#endif

// Make sure nobody can resize the app under any platform
this->setFixedSize(this->width(), this->height());
this->setWindowTitle(this->windowTitle() + " - v" + APP_VERSION);

// Fetch settings from storage and/or write defaults
this->initSettings();
this->initSettings(false, false);

// Populate UI with the loaded settings
this->reloadUiState();
Expand All @@ -49,17 +53,16 @@ LoFloccus::LoFloccus(QWidget *parent)
showMinimized();
}
if (settings->value("startminimized").toBool() && settings->value("hidetosystray").toBool()) {
#ifdef Q_OS_DARWIN
darwinBridge->makeAppAccessory();
#endif
sysTray->showMessage("LoFloccus", "LoFloccus is running in the background. Click the menu for more options.", appIcon);
}

// Start the server with the app if required
if (settings->value("startopen").toBool()) {
this->startServer();
}

// Start the server with the app
this->startServer();
}

#ifdef Q_OS_WIN
void LoFloccus::closeEvent(QCloseEvent *event)
{
if (minimizeAndCloseToTray) {
Expand All @@ -75,10 +78,12 @@ void LoFloccus::hideEvent(QHideEvent *event)
event->accept();
if (minimizeAndCloseToTray) {
hide();
#ifdef Q_OS_DARWIN
darwinBridge->makeAppAccessory();
#endif
sysTray->showMessage("LoFloccus", "LoFloccus is running in the background. Click the menu for more options.", appIcon);
}
}
#endif

LoFloccus::~LoFloccus()
{
Expand All @@ -90,10 +95,29 @@ LoFloccus::~LoFloccus()
delete ui;
}

void LoFloccus::initSettings()
{
// Initialized a shared settings object with the appropriate path
settings = new QSettings(QStandardPaths::writableLocation(QStandardPaths::AppConfigLocation) + "/settings.ini", QSettings::IniFormat);
void LoFloccus::initSettings(bool makeExistingSettingsPortable = false, bool makeExistingSettingsLocal = false)
{
QString localSettingsFile = QStandardPaths::writableLocation(QStandardPaths::AppConfigLocation) + "/settings.ini";
QString portableSettingsFile = "lofloccus-settings.ini";

// Deal with settings location move
if (makeExistingSettingsPortable) {
if (QFile::exists(portableSettingsFile)) {
QFile::remove(portableSettingsFile);
}
QFile::copy(localSettingsFile, portableSettingsFile);
QFile::remove(localSettingsFile);
}
if (makeExistingSettingsLocal) {
if (QFile::exists(localSettingsFile)) {
QFile::remove(localSettingsFile);
}
QFile::copy(portableSettingsFile, localSettingsFile);
QFile::remove(portableSettingsFile);
}

// Initialize a shared settings object with the appropriate path
settings = new QSettings(QFile::exists(portableSettingsFile) ? portableSettingsFile : localSettingsFile, QSettings::IniFormat);

// Generate random defaults for port and password
QString defaultPort = QString::number(QRandomGenerator::global()->bounded(40000, 65535));
Expand All @@ -107,15 +131,14 @@ void LoFloccus::initSettings()
settings->setValue("serveruser", settings->value("serveruser", "floccus"));
settings->setValue("serverpasswd", settings->value("serverpasswd", defaultPasswd));

settings->setValue("startopen", settings->value("startopen", false));
settings->setValue("startminimized", settings->value("startminimized", false));
settings->setValue("hidetosystray", settings->value("hidetosystray", false));
settings->setValue("sharednetwork", settings->value("sharednetwork", false));
settings->setValue("portablemode", settings->value("portablemode", false));
}

void LoFloccus::reloadUiState()
{
ui->btn_server_control->setText(running ? "Stop LoFloccus Server": "Start LoFloccus Server");
ui->xbel_path->setText(settings->value("serverpath").toString());

// Take care of the server addresses, might be just local or all IPs of the machine
Expand All @@ -130,10 +153,10 @@ void LoFloccus::reloadUiState()
ui->srv_user->setText(settings->value("serveruser").toString());
ui->srv_passwd->setText(settings->value("serverpasswd").toString());

ui->startopen->setChecked(settings->value("startopen").toBool());
ui->startminimized->setChecked(settings->value("startminimized").toBool());
ui->hidetosystray->setChecked(settings->value("hidetosystray").toBool());
ui->sharednetwork->setChecked(settings->value("sharednetwork").toBool());
ui->portablemode->setChecked(settings->value("portablemode").toBool());
}

void LoFloccus::initSystray()
Expand All @@ -147,6 +170,9 @@ void LoFloccus::initSystray()

QAction *openAction = new QAction("Open LoFloccus", this);
connect(openAction, &QAction::triggered, [this]() {
#ifdef Q_OS_DARWIN
darwinBridge->makeAppRegular();
#endif
showNormal();
activateWindow();
});
Expand Down Expand Up @@ -184,25 +210,19 @@ void LoFloccus::restartServer()

void LoFloccus::startServer()
{
ui->btn_server_control->setDisabled(true);
ui->btn_server_control->setChecked(false);
serverStart(settings->value("serveraddr").toString().toUtf8().data(),
settings->value("serverport").toString().toUtf8().data(),
settings->value("serverpath").toString().toUtf8().data(),
settings->value("serveruser").toString().toUtf8().data(),
settings->value("serverpasswd").toString().toUtf8().data()
);
ui->btn_server_control->setDisabled(false);
running = true;
this->reloadUiState();
}

void LoFloccus::stopServer()
{
ui->btn_server_control->setDisabled(true);
ui->btn_server_control->setChecked(false);
serverStop();
ui->btn_server_control->setDisabled(false);
running = false;
this->reloadUiState();
}
Expand All @@ -225,16 +245,6 @@ QList<QString> LoFloccus::getSystemIPAddresses(bool locals = true, bool v4 = tru
return returnList;
}


void LoFloccus::on_btn_server_control_clicked()
{
if (running) {
this->stopServer();
} else {
this->startServer();
}
}

void LoFloccus::on_btn_xbel_localtion_clicked()
{
QString dir = QFileDialog::getExistingDirectory(this,
Expand All @@ -245,17 +255,19 @@ void LoFloccus::on_btn_xbel_localtion_clicked()
return;
}
settings->setValue("serverpath", dir);
if (!running) {
this->reloadUiState();
}
this->restartServer();
}



void LoFloccus::on_startopen_clicked()
void LoFloccus::on_portablemode_clicked()
{
settings->setValue("startopen", ui->startopen->isChecked());
if (ui->portablemode->isChecked()) {
this->initSettings(true, false);
} else {
this->initSettings(false, true);
}
settings->setValue("portablemode", ui->portablemode->isChecked());
}

void LoFloccus::on_startminimized_clicked()
Expand All @@ -275,3 +287,4 @@ void LoFloccus::on_sharednetwork_clicked()
settings->setValue("serveraddr", ui->sharednetwork->isChecked() ? "0.0.0.0" : "127.0.0.1");
this->restartServer();
}

23 changes: 11 additions & 12 deletions LoFloccus/lofloccus.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@
#include <QSystemTrayIcon>
#include <QMenu>

#ifdef Q_OS_DARWIN
#include "platformdarwin.h"
#endif

QT_BEGIN_NAMESPACE
namespace Ui { class LoFloccus; }
QT_END_NAMESPACE
Expand All @@ -19,25 +23,16 @@ class LoFloccus : public QMainWindow
~LoFloccus();
QIcon appIcon;



private slots:
void on_btn_server_control_clicked();
void on_btn_xbel_localtion_clicked();

void on_startopen_clicked();

void on_startminimized_clicked();

void on_hidetosystray_clicked();

void on_sharednetwork_clicked();
void on_portablemode_clicked();

protected:
#ifdef Q_OS_WIN
void closeEvent(QCloseEvent *event) override;
void hideEvent(QHideEvent *event) override;
#endif

private:
bool minimizeAndCloseToTray;
Expand All @@ -46,10 +41,14 @@ private slots:
QSettings *settings;
QSystemTrayIcon *sysTray;

#ifdef Q_OS_DARWIN
PlatformDarwin *darwinBridge;
#endif

Ui::LoFloccus *ui;
void initSettings();
void reloadUiState();

void initSettings(bool makeExistingSettingsPortable, bool makeExistingSettingsLocal);
void reloadUiState();
void startServer();
void stopServer();
void restartServer();
Expand Down
Loading

0 comments on commit e5d1292

Please sign in to comment.