Support dragging and dropping of files onto app icon

Tested on macos and windows.  Drag and drop files onto either the dock icon or task bar icon once SavvyCCAN is running
This commit is contained in:
Chris Whiteford
2021-05-25 11:39:24 -04:00
parent 820ad1186c
commit 51c25f0072
6 changed files with 123 additions and 4 deletions
+45
View File
@@ -0,0 +1,45 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleExecutable</key>
<string>${EXECUTABLE_NAME}</string>
<key>CFBundleIconFile</key>
<string>${ASSETCATALOG_COMPILER_APPICON_NAME}</string>
<key>CFBundleIdentifier</key>
<string>${PRODUCT_BUNDLE_IDENTIFIER}</string>
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleSignature</key>
<string>${QMAKE_PKGINFO_TYPEINFO}</string>
<key>LSMinimumSystemVersion</key>
<string>${MACOSX_DEPLOYMENT_TARGET}</string>
<key>NSPrincipalClass</key>
<string>NSApplication</string>
<key>NSSupportsAutomaticGraphicsSwitching</key>
<true/>
<key>CFBundleDocumentTypes</key>
<array>
<dict>
<key>CFBundleTypeExtensions</key>
<array>
<string>asc</string>
<string>avc</string>
<string>blf</string>
<string>can</string>
<string>crt</string>
<string>crtd</string>
<string>csv</string>
<string>evc</string>
<string>log</string>
<string>qcc</string>
<string>trace</string>
<string>trc</string>
<string>txt</string>
</array>
<key>CFBundleTypeRole</key>
<string>Viewer</string>
</dict>
</array>
</dict>
</plist>
+3
View File
@@ -16,6 +16,9 @@ DEFINES += QCUSTOMPLOT_USE_OPENGL
TARGET = SavvyCAN TARGET = SavvyCAN
TEMPLATE = app TEMPLATE = app
QMAKE_INFO_PLIST = Info.plist.template
ICON = icons/SavvyIcon.icns
SOURCES += main.cpp\ SOURCES += main.cpp\
connections/mqtt_bus.cpp \ connections/mqtt_bus.cpp \
mqtt/qmqtt_client.cpp \ mqtt/qmqtt_client.cpp \
Binary file not shown.
+29 -4
View File
@@ -1,9 +1,30 @@
#include "mainwindow.h" #include "mainwindow.h"
#include <QApplication> #include <QApplication>
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<QFileOpenEvent *>(event);
mainWindow->handleDroppedFile(openEvent->file());
}
return QApplication::event(event);
}
};
int main(int argc, char *argv[]) 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. //Add a local path for Qt extensions, to allow for per-application extensions.
a.addLibraryPath("plugins"); a.addLibraryPath("plugins");
@@ -14,7 +35,7 @@ int main(int argc, char *argv[])
a.setOrganizationDomain("evtv.me"); a.setOrganizationDomain("evtv.me");
QSettings::setDefaultFormat(QSettings::IniFormat); QSettings::setDefaultFormat(QSettings::IniFormat);
MainWindow w; a.mainWindow = new MainWindow();
QSettings settings; QSettings settings;
int fontSize = settings.value("Main/FontSize", 9).toUInt(); int fontSize = settings.value("Main/FontSize", 9).toUInt();
@@ -22,7 +43,11 @@ int main(int argc, char *argv[])
sysFont.setPointSize(fontSize); sysFont.setPointSize(fontSize);
a.setFont(sysFont); a.setFont(sysFont);
w.show(); a.mainWindow->show();
return a.exec(); int retCode = a.exec();
delete a.mainWindow; a.mainWindow = NULL;
return retCode;
} }
+44
View File
@@ -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<CANFrame> 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() void MainWindow::handleSaveFile()
{ {
QString filename; QString filename;
+2
View File
@@ -54,6 +54,8 @@ public:
CANFrameModel * getCANFrameModel(); CANFrameModel * getCANFrameModel();
~MainWindow(); ~MainWindow();
void handleDroppedFile(const QString &filename);
private slots: private slots:
void handleLoadFile(); void handleLoadFile();
void handleSaveFile(); void handleSaveFile();