Skip to content

Commit c25ba73

Browse files
committed
Pass command line argument to MainWindow, added command unlicense which reverts back to the default unlicensed state.
1 parent b417880 commit c25ba73

File tree

5 files changed

+26
-7
lines changed

5 files changed

+26
-7
lines changed

src/commandserver.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,6 @@ void CommandServer::processArg(const QString& arg)
127127
emit gotFile(arg);
128128
}
129129
else {
130-
LOGGER(debug) << "CommandServer::handleConnection - unhandled arg: " << arg.toStdString() << std::endl;
130+
emit gotCommand(arg);
131131
}
132132
}

src/commandserver.h

+1
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ class CommandServer : public QObject
3333
signals:
3434
void gotUrl(const QUrl& url);
3535
void gotFile(const QString& fileName);
36+
void gotCommand(const QString& command);
3637

3738
private slots:
3839
void handleConnection();

src/main.cpp

+9-4
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,13 @@ int main(int argc, char* argv[])
4242
msgBox.setText(QMessageBox::tr("Warning: Failed to create vault data directory."));
4343
msgBox.exec();
4444
}
45-
46-
INIT_LOGGER((APPDATADIR + "/debug.log").toStdString().c_str());
47-
LOGGER(debug) << std::endl << std::endl << std::endl << std::endl << QDateTime::currentDateTime().toString().toStdString() << std::endl;
4845

46+
// Check whether another instance is already running. If so, send it commands and exit.
4947
CommandServer commandServer(&app);
5048
if (commandServer.processArgs(argc, argv)) exit(0);
5149

50+
INIT_LOGGER((APPDATADIR + "/debug.log").toStdString().c_str());
51+
LOGGER(debug) << std::endl << std::endl << std::endl << std::endl << QDateTime::currentDateTime().toString().toStdString() << std::endl;
5252
LOGGER(debug) << "Vault started." << std::endl;
5353

5454
SplashScreen splash;
@@ -68,6 +68,7 @@ int main(int argc, char* argv[])
6868
else {
6969
app.connect(&commandServer, SIGNAL(gotUrl(const QUrl&)), &mainWin, SLOT(processUrl(const QUrl&)));
7070
app.connect(&commandServer, SIGNAL(gotFile(const QString&)), &mainWin, SLOT(processFile(const QString&)));
71+
app.connect(&commandServer, SIGNAL(gotCommand(const QString&)), &mainWin, SLOT(processCommand(const QString&)));
7172
}
7273

7374
app.processEvents();
@@ -95,7 +96,11 @@ int main(int argc, char* argv[])
9596
if (!mainWin.isLicenseAccepted()) {
9697
//Display license agreement
9798
AcceptLicenseDialog acceptLicenseDialog;
98-
if (!acceptLicenseDialog.exec()) return -1;
99+
if (!acceptLicenseDialog.exec()) {
100+
LOGGER(error) << "License agreement not accepted." << std::endl;
101+
return -1;
102+
}
103+
LOGGER(debug) << "License agreement accepted." << std::endl;
99104
mainWin.setLicenseAccepted(true);
100105
mainWin.saveSettings();
101106
}

src/mainwindow.cpp

+12
Original file line numberDiff line numberDiff line change
@@ -1216,6 +1216,18 @@ void MainWindow::processFile(const QString& fileName)
12161216
}
12171217
}
12181218

1219+
void MainWindow::processCommand(const QString& command)
1220+
{
1221+
if (command == "unlicense") {
1222+
LOGGER(trace) << "MainWindow::processCommand - " << command.toStdString() << std::endl;
1223+
licenseAccepted = false;
1224+
saveSettings();
1225+
}
1226+
else {
1227+
LOGGER(trace) << "MainWindow::processCommand - unhandled command: " << command.toStdString() << std::endl;
1228+
}
1229+
}
1230+
12191231
void MainWindow::createActions()
12201232
{
12211233
// application actions

src/mainwindow.h

+3-2
Original file line numberDiff line numberDiff line change
@@ -174,10 +174,11 @@ private slots:
174174
// STATUS UPDATES
175175
void errorStatus(const QString& message);
176176

177-
//////////////////////
178-
// URL/FILE OPERATIONS
177+
//////////////////////////////
178+
// URL/FILE/COMMAND OPERATIONS
179179
void processUrl(const QUrl& url);
180180
void processFile(const QString& fileName);
181+
void processCommand(const QString& command);
181182

182183
private:
183184
// License accepted?

0 commit comments

Comments
 (0)