rewrite signaling to CBOR; support multiple file signaling
parent
22f5b0502d
commit
06230dde55
8
notes
8
notes
|
@ -33,13 +33,11 @@ parameters {
|
|||
TODO {
|
||||
immediate frontburner {
|
||||
multi-window accounting {
|
||||
rewrite signaling using CBOR to support file lists
|
||||
support opening multiple files at once
|
||||
(if no successes, open new project window)
|
||||
- rewrite signaling using CBOR to support file lists
|
||||
- support opening multiple files at once on launch
|
||||
- (if no successes, open new project window)
|
||||
|
||||
change %f to %F once list support is implemented
|
||||
|
||||
array?
|
||||
}
|
||||
|
||||
revert action
|
||||
|
|
|
@ -14,6 +14,13 @@
|
|||
#include <QSurfaceFormat>
|
||||
#include <QFontDatabase>
|
||||
|
||||
#include <QCborMap>
|
||||
#include <QCborArray>
|
||||
#include <QCborStreamReader>
|
||||
#include <QCborStreamWriter>
|
||||
|
||||
#define qs QStringLiteral
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
qRegisterMetaType<Xybrid::Data::Port>();
|
||||
// enable antialiasing on accelerated graphicsview
|
||||
|
@ -26,23 +33,34 @@ int main(int argc, char *argv[]) {
|
|||
QCommandLineParser cl;
|
||||
cl.addHelpOption();
|
||||
cl.addVersionOption();
|
||||
cl.addPositionalArgument("[project]", QApplication::translate("main", "Project file to open."));
|
||||
cl.addPositionalArgument("[project...]", QApplication::translate("main", "Project file(s) to open."));
|
||||
|
||||
cl.process(a);
|
||||
auto args = cl.positionalArguments();
|
||||
QString fileName = args.size() >= 1 ? args.at(0) : QString();
|
||||
if (!fileName.isEmpty()) fileName = QFileInfo(fileName).absoluteFilePath(); // canonicize
|
||||
|
||||
QString userName = qEnvironmentVariable("USER");
|
||||
if (userName.isEmpty()) userName = qEnvironmentVariable("USERNAME");
|
||||
|
||||
QString socketName = QStringLiteral("xybrid-ipc-%1").arg(userName);
|
||||
QString socketName = qs("xybrid-ipc-%1").arg(userName);
|
||||
|
||||
QLocalSocket tryc;
|
||||
tryc.connectToServer(socketName);
|
||||
tryc.waitForConnected(1000); // wait for connection attempt (can't hang on local)
|
||||
if (tryc.isOpen()) { // if server already exists, give it the signal and exit
|
||||
tryc.write(fileName.toUtf8());
|
||||
QCborArray root;
|
||||
root << "open";
|
||||
|
||||
QCborArray lst;
|
||||
for (auto& fn : args) {
|
||||
QFileInfo fi(fn);
|
||||
if (!fi.exists()) continue;
|
||||
lst << fi.absoluteFilePath();
|
||||
}
|
||||
root << lst;
|
||||
|
||||
QCborStreamWriter csw(&tryc);
|
||||
root.toCborValue().toCbor(csw);
|
||||
|
||||
tryc.waitForBytesWritten();
|
||||
tryc.close();
|
||||
return 0;
|
||||
|
@ -56,16 +74,27 @@ int main(int argc, char *argv[]) {
|
|||
auto s = srv.nextPendingConnection();
|
||||
s->waitForDisconnected();
|
||||
|
||||
auto fileName = QString::fromUtf8(s->readAll());
|
||||
|
||||
if (auto w = Xybrid::MainWindow::projectWindow(fileName); w) w->tryFocus();
|
||||
else {
|
||||
w = new Xybrid::MainWindow(nullptr, fileName);
|
||||
if (w->getProject()) w->show();
|
||||
else (w->deleteLater());
|
||||
}
|
||||
|
||||
QCborStreamReader csr(s);
|
||||
auto root = QCborValue::fromCbor(csr).toArray();
|
||||
s->deleteLater();
|
||||
|
||||
auto cmd = root.at(0).toString();
|
||||
|
||||
if (cmd == "open") {
|
||||
auto lst = root.at(1).toArray();
|
||||
if (lst.isEmpty()) {
|
||||
auto w = new Xybrid::MainWindow(nullptr);
|
||||
w->show();
|
||||
}
|
||||
for (auto e : lst) {
|
||||
QFileInfo fi(e.toString());
|
||||
if (!fi.exists()) continue;
|
||||
auto fileName = fi.absoluteFilePath();
|
||||
auto w = new Xybrid::MainWindow(nullptr, fileName);
|
||||
if (w->getProject()) w->show();
|
||||
else (w->deleteLater());
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// make sure bundled fonts are loaded
|
||||
|
@ -90,7 +119,7 @@ int main(int argc, char *argv[]) {
|
|||
}
|
||||
|
||||
if (!opn) { // always show one window on launch
|
||||
auto* w = new Xybrid::MainWindow(nullptr);
|
||||
auto w = new Xybrid::MainWindow(nullptr);
|
||||
w->show();
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue