diff --git a/Info.plist.template b/Info.plist.template new file mode 100644 index 0000000..763e54e --- /dev/null +++ b/Info.plist.template @@ -0,0 +1,45 @@ + + + + + CFBundleExecutable + ${EXECUTABLE_NAME} + CFBundleIconFile + ${ASSETCATALOG_COMPILER_APPICON_NAME} + CFBundleIdentifier + ${PRODUCT_BUNDLE_IDENTIFIER} + CFBundlePackageType + APPL + CFBundleSignature + ${QMAKE_PKGINFO_TYPEINFO} + LSMinimumSystemVersion + ${MACOSX_DEPLOYMENT_TARGET} + NSPrincipalClass + NSApplication + NSSupportsAutomaticGraphicsSwitching + + CFBundleDocumentTypes + + + CFBundleTypeExtensions + + asc + avc + blf + can + crt + crtd + csv + evc + log + qcc + trace + trc + txt + + CFBundleTypeRole + Viewer + + + + diff --git a/SavvyCAN.pro b/SavvyCAN.pro index acb4110..4e6b2ea 100644 --- a/SavvyCAN.pro +++ b/SavvyCAN.pro @@ -16,6 +16,9 @@ DEFINES += QCUSTOMPLOT_USE_OPENGL TARGET = SavvyCAN TEMPLATE = app +QMAKE_INFO_PLIST = Info.plist.template +ICON = icons/SavvyIcon.icns + SOURCES += main.cpp\ connections/mqtt_bus.cpp \ mqtt/qmqtt_client.cpp \ diff --git a/icons/SavvyIcon.icns b/icons/SavvyIcon.icns new file mode 100644 index 0000000..78cb5f9 Binary files /dev/null and b/icons/SavvyIcon.icns differ diff --git a/main.cpp b/main.cpp index 847a380..c9466dc 100644 --- a/main.cpp +++ b/main.cpp @@ -1,9 +1,30 @@ #include "mainwindow.h" #include +class SavvyCANApplication : public QApplication +{ +public: + MainWindow *mainWindow; + + SavvyCANApplication(int &argc, char **argv) : QApplication(argc, argv) + { + } + + bool event(QEvent *event) override + { + if (event->type() == QEvent::FileOpen) + { + QFileOpenEvent *openEvent = static_cast(event); + mainWindow->handleDroppedFile(openEvent->file()); + } + + return QApplication::event(event); + } +}; + int main(int argc, char *argv[]) { - QApplication a(argc, argv); + SavvyCANApplication a(argc, argv); //Add a local path for Qt extensions, to allow for per-application extensions. a.addLibraryPath("plugins"); @@ -14,7 +35,7 @@ int main(int argc, char *argv[]) a.setOrganizationDomain("evtv.me"); QSettings::setDefaultFormat(QSettings::IniFormat); - MainWindow w; + a.mainWindow = new MainWindow(); QSettings settings; int fontSize = settings.value("Main/FontSize", 9).toUInt(); @@ -22,7 +43,11 @@ int main(int argc, char *argv[]) sysFont.setPointSize(fontSize); a.setFont(sysFont); - w.show(); + a.mainWindow->show(); - return a.exec(); + int retCode = a.exec(); + + delete a.mainWindow; a.mainWindow = NULL; + + return retCode; } diff --git a/mainwindow.cpp b/mainwindow.cpp index be72ea0..c9ae16d 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -807,6 +807,50 @@ void MainWindow::handleLoadFile() } } +void MainWindow::handleDroppedFile(const QString &filename) +{ + QProgressDialog progress(qApp->activeWindow()); + progress.setWindowModality(Qt::WindowModal); + progress.setLabelText("Loading file..."); + progress.setCancelButton(nullptr); + progress.setRange(0,0); + progress.setMinimumDuration(0); + progress.show(); + + QVector loadedFrames; + bool loadResult = FrameFileIO::autoDetectLoadFile(filename, &loadedFrames); + + progress.cancel(); + + if (!loadResult) + { + if (loadedFrames.count() > 0) //only ask if at least one frame was decoded. + { + QMessageBox::StandardButton confirmDialog = QMessageBox::question(this, "Error Loading", "Do you want to salvage what could be loaded?", + QMessageBox::Yes|QMessageBox::No); + if (confirmDialog == QMessageBox::Yes) + { + loadResult = true; + } + } + } + + if (loadResult) + { + ui->canFramesView->scrollToTop(); + model->clearFrames(); + model->insertFrames(loadedFrames); + loadedFileName = filename; + model->recalcOverwrite(); + ui->lbNumFrames->setText(QString::number(model->rowCount())); + if (ui->cbAutoScroll->isChecked()) ui->canFramesView->scrollToBottom(); + + updateFileStatus(); + emit framesUpdated(-1); + } +} + + void MainWindow::handleSaveFile() { QString filename; diff --git a/mainwindow.h b/mainwindow.h index 0513ebb..f773ad5 100644 --- a/mainwindow.h +++ b/mainwindow.h @@ -54,6 +54,8 @@ public: CANFrameModel * getCANFrameModel(); ~MainWindow(); + void handleDroppedFile(const QString &filename); + private slots: void handleLoadFile(); void handleSaveFile();