Skip to content

Commit e5d1292

Browse files
committed
Full macOS support, portable more and more
1 parent 94782d5 commit e5d1292

File tree

9 files changed

+128
-355
lines changed

9 files changed

+128
-355
lines changed

LoFloccus/LoFloccus.pro

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ FORMS += \
2626
lofloccus.ui
2727

2828
# Generic for all builds
29-
VERSION = 1.2.0
29+
VERSION = 1.2.1
3030
DEFINES += APP_VERSION=\\\"$$VERSION\\\"
3131
INCLUDEPATH += $${PWD}/libs
3232

@@ -44,6 +44,11 @@ mac {
4444
ICON = assets/icon.icns
4545
QMAKE_TARGET_BUNDLE_PREFIX = "com.tcb13"
4646
LIBS += -L$${PWD}/libs -lLoFloccusDavDarwin
47+
48+
SOURCES += platformdarwin.mm
49+
HEADERS += platformdarwin.h
50+
LIBS += -framework Foundation
51+
LIBS += -framework AppKit
4752
}
4853

4954

@@ -59,12 +64,13 @@ RESOURCES += \
5964

6065
# Static Builds
6166
QTPREFIX=$$[QT_INSTALL_PREFIX]
62-
equals(QTPREFIX, "C:/Qt-Static/Qt-5.14.2"){
67+
equals(QTPREFIX, "C:/Qt-Static/Qt-5.14.2") || equals(QTPREFIX, "/Users/tcb13/Qt-Static/Qt-5.12.12") {
6368
message("--STATIC BUILD--")
6469
CONFIG += qt static
65-
QMAKE_LFLAGS += -static-libgcc -static-libstdc++
70+
win32 {
71+
QMAKE_LFLAGS += -static-libgcc -static-libstdc++
72+
}
73+
6674
} else {
6775
message("--NON-STATIC BUILD--")
6876
}
69-
70-

LoFloccus/LoFloccus.pro.user

Lines changed: 10 additions & 254 deletions
Large diffs are not rendered by default.

LoFloccus/libs/libLoFloccusDav.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,9 @@ Complied with:
88
How to install/compile this as a static library:
99
1. go get "golang.org/x/net/webdav"
1010
2. Build ir for your architecture:
11-
2.1. Windows: go build -buildmode c-archive -o libLoFloccusDavWin64.a libLoFloccusDav.go
12-
2.2. macOS: go build -buildmode c-shared -o libLoFloccusDavDarwin.a libLoFloccusDav.go
11+
2.1. Windows (dev/release): go build -buildmode c-archive -o libLoFloccusDavWin64.a libLoFloccusDav.go
12+
2.2. macOS (dev): go build -buildmode c-shared -o libLoFloccusDavDarwin.a libLoFloccusDav.go
13+
2.3. macOS (release): go build -buildmode c-archive -o libLoFloccusDavDarwin.a libLoFloccusDav.go
1314
*/
1415

1516
package main

LoFloccus/lofloccus.cpp

Lines changed: 49 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,16 @@ LoFloccus::LoFloccus(QWidget *parent)
2828
appIcon = QIcon(":/assets/icon.ico");
2929
running = false;
3030

31+
#ifdef Q_OS_DARWIN
32+
darwinBridge = new PlatformDarwin();
33+
#endif
34+
3135
// Make sure nobody can resize the app under any platform
3236
this->setFixedSize(this->width(), this->height());
3337
this->setWindowTitle(this->windowTitle() + " - v" + APP_VERSION);
3438

3539
// Fetch settings from storage and/or write defaults
36-
this->initSettings();
40+
this->initSettings(false, false);
3741

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

55-
// Start the server with the app if required
56-
if (settings->value("startopen").toBool()) {
57-
this->startServer();
58-
}
59-
62+
// Start the server with the app
63+
this->startServer();
6064
}
6165

62-
#ifdef Q_OS_WIN
6366
void LoFloccus::closeEvent(QCloseEvent *event)
6467
{
6568
if (minimizeAndCloseToTray) {
@@ -75,10 +78,12 @@ void LoFloccus::hideEvent(QHideEvent *event)
7578
event->accept();
7679
if (minimizeAndCloseToTray) {
7780
hide();
81+
#ifdef Q_OS_DARWIN
82+
darwinBridge->makeAppAccessory();
83+
#endif
7884
sysTray->showMessage("LoFloccus", "LoFloccus is running in the background. Click the menu for more options.", appIcon);
7985
}
8086
}
81-
#endif
8287

8388
LoFloccus::~LoFloccus()
8489
{
@@ -90,10 +95,29 @@ LoFloccus::~LoFloccus()
9095
delete ui;
9196
}
9297

93-
void LoFloccus::initSettings()
94-
{
95-
// Initialized a shared settings object with the appropriate path
96-
settings = new QSettings(QStandardPaths::writableLocation(QStandardPaths::AppConfigLocation) + "/settings.ini", QSettings::IniFormat);
98+
void LoFloccus::initSettings(bool makeExistingSettingsPortable = false, bool makeExistingSettingsLocal = false)
99+
{
100+
QString localSettingsFile = QStandardPaths::writableLocation(QStandardPaths::AppConfigLocation) + "/settings.ini";
101+
QString portableSettingsFile = "lofloccus-settings.ini";
102+
103+
// Deal with settings location move
104+
if (makeExistingSettingsPortable) {
105+
if (QFile::exists(portableSettingsFile)) {
106+
QFile::remove(portableSettingsFile);
107+
}
108+
QFile::copy(localSettingsFile, portableSettingsFile);
109+
QFile::remove(localSettingsFile);
110+
}
111+
if (makeExistingSettingsLocal) {
112+
if (QFile::exists(localSettingsFile)) {
113+
QFile::remove(localSettingsFile);
114+
}
115+
QFile::copy(portableSettingsFile, localSettingsFile);
116+
QFile::remove(portableSettingsFile);
117+
}
118+
119+
// Initialize a shared settings object with the appropriate path
120+
settings = new QSettings(QFile::exists(portableSettingsFile) ? portableSettingsFile : localSettingsFile, QSettings::IniFormat);
97121

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

110-
settings->setValue("startopen", settings->value("startopen", false));
111134
settings->setValue("startminimized", settings->value("startminimized", false));
112135
settings->setValue("hidetosystray", settings->value("hidetosystray", false));
113136
settings->setValue("sharednetwork", settings->value("sharednetwork", false));
137+
settings->setValue("portablemode", settings->value("portablemode", false));
114138
}
115139

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

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

133-
ui->startopen->setChecked(settings->value("startopen").toBool());
134156
ui->startminimized->setChecked(settings->value("startminimized").toBool());
135157
ui->hidetosystray->setChecked(settings->value("hidetosystray").toBool());
136158
ui->sharednetwork->setChecked(settings->value("sharednetwork").toBool());
159+
ui->portablemode->setChecked(settings->value("portablemode").toBool());
137160
}
138161

139162
void LoFloccus::initSystray()
@@ -147,6 +170,9 @@ void LoFloccus::initSystray()
147170

148171
QAction *openAction = new QAction("Open LoFloccus", this);
149172
connect(openAction, &QAction::triggered, [this]() {
173+
#ifdef Q_OS_DARWIN
174+
darwinBridge->makeAppRegular();
175+
#endif
150176
showNormal();
151177
activateWindow();
152178
});
@@ -184,25 +210,19 @@ void LoFloccus::restartServer()
184210

185211
void LoFloccus::startServer()
186212
{
187-
ui->btn_server_control->setDisabled(true);
188-
ui->btn_server_control->setChecked(false);
189213
serverStart(settings->value("serveraddr").toString().toUtf8().data(),
190214
settings->value("serverport").toString().toUtf8().data(),
191215
settings->value("serverpath").toString().toUtf8().data(),
192216
settings->value("serveruser").toString().toUtf8().data(),
193217
settings->value("serverpasswd").toString().toUtf8().data()
194218
);
195-
ui->btn_server_control->setDisabled(false);
196219
running = true;
197220
this->reloadUiState();
198221
}
199222

200223
void LoFloccus::stopServer()
201224
{
202-
ui->btn_server_control->setDisabled(true);
203-
ui->btn_server_control->setChecked(false);
204225
serverStop();
205-
ui->btn_server_control->setDisabled(false);
206226
running = false;
207227
this->reloadUiState();
208228
}
@@ -225,16 +245,6 @@ QList<QString> LoFloccus::getSystemIPAddresses(bool locals = true, bool v4 = tru
225245
return returnList;
226246
}
227247

228-
229-
void LoFloccus::on_btn_server_control_clicked()
230-
{
231-
if (running) {
232-
this->stopServer();
233-
} else {
234-
this->startServer();
235-
}
236-
}
237-
238248
void LoFloccus::on_btn_xbel_localtion_clicked()
239249
{
240250
QString dir = QFileDialog::getExistingDirectory(this,
@@ -245,17 +255,19 @@ void LoFloccus::on_btn_xbel_localtion_clicked()
245255
return;
246256
}
247257
settings->setValue("serverpath", dir);
248-
if (!running) {
249-
this->reloadUiState();
250-
}
251258
this->restartServer();
252259
}
253260

254261

255262

256-
void LoFloccus::on_startopen_clicked()
263+
void LoFloccus::on_portablemode_clicked()
257264
{
258-
settings->setValue("startopen", ui->startopen->isChecked());
265+
if (ui->portablemode->isChecked()) {
266+
this->initSettings(true, false);
267+
} else {
268+
this->initSettings(false, true);
269+
}
270+
settings->setValue("portablemode", ui->portablemode->isChecked());
259271
}
260272

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

LoFloccus/lofloccus.h

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@
66
#include <QSystemTrayIcon>
77
#include <QMenu>
88

9+
#ifdef Q_OS_DARWIN
10+
#include "platformdarwin.h"
11+
#endif
12+
913
QT_BEGIN_NAMESPACE
1014
namespace Ui { class LoFloccus; }
1115
QT_END_NAMESPACE
@@ -19,25 +23,16 @@ class LoFloccus : public QMainWindow
1923
~LoFloccus();
2024
QIcon appIcon;
2125

22-
23-
2426
private slots:
25-
void on_btn_server_control_clicked();
2627
void on_btn_xbel_localtion_clicked();
27-
28-
void on_startopen_clicked();
29-
3028
void on_startminimized_clicked();
31-
3229
void on_hidetosystray_clicked();
33-
3430
void on_sharednetwork_clicked();
31+
void on_portablemode_clicked();
3532

3633
protected:
37-
#ifdef Q_OS_WIN
3834
void closeEvent(QCloseEvent *event) override;
3935
void hideEvent(QHideEvent *event) override;
40-
#endif
4136

4237
private:
4338
bool minimizeAndCloseToTray;
@@ -46,10 +41,14 @@ private slots:
4641
QSettings *settings;
4742
QSystemTrayIcon *sysTray;
4843

44+
#ifdef Q_OS_DARWIN
45+
PlatformDarwin *darwinBridge;
46+
#endif
47+
4948
Ui::LoFloccus *ui;
50-
void initSettings();
51-
void reloadUiState();
5249

50+
void initSettings(bool makeExistingSettingsPortable, bool makeExistingSettingsLocal);
51+
void reloadUiState();
5352
void startServer();
5453
void stopServer();
5554
void restartServer();

0 commit comments

Comments
 (0)