@@ -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
6366void 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
8388LoFloccus::~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
116140void 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
139162void 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
185211void 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
200223void 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-
238248void 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
261273void 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+
0 commit comments