Skip to content

Commit

Permalink
Merge pull request #128 from orange-vertex/open_from_filesystem_macos
Browse files Browse the repository at this point in the history
Open from filesystem macos
  • Loading branch information
pklampros authored Feb 22, 2018
2 parents 7877516 + 82b0d9c commit a1c7a8e
Show file tree
Hide file tree
Showing 10 changed files with 135 additions and 83 deletions.
12 changes: 11 additions & 1 deletion GuiApp/GuiApp.pro
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ DEFINES += _DEPTHMAP
TEMPLATE = app
TARGET = depthmapX
ICON = icons/depthmapX.icns
SOURCES = main.cpp
SOURCES = main.cpp \
coreapplication.cpp

win32:RC_ICONS += icons/depthmapX.ico

Expand All @@ -25,4 +26,13 @@ win32:LIBS += -lOpenGl32 -lglu32 -lgdi32
HEADERS += \
coreapplication.h

mac {
QMAKE_INFO_PLIST = resources/Info.plist
BUNDLE_RESOURCES.files = icons/graph.icns
BUNDLE_RESOURCES.path = Contents/Resources
QMAKE_BUNDLE_DATA += BUNDLE_RESOURCES
}

FORMS += \
../depthmapX/UI/ColourScaleDlg.ui

54 changes: 54 additions & 0 deletions GuiApp/coreapplication.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
// Copyright (C) 2017 Petros Koutsolampros

// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.

// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.

#include "GuiApp/coreapplication.h"
#include <QSplashScreen>
#include <QDesktopWidget>

int CoreApplication::exec() {
SettingsImpl settings(new DefaultSettingsFactory);

if (!settings.readSetting(SettingTag::licenseAccepted, false).toBool())
{
auto dummy = MainWindowFactory::getLicenseDialog();
dummy->setModal(true);
dummy->setWindowTitle(TITLE_BASE);
dummy->exec();
if ( dummy->result() == QDialog::Rejected) {
return 0;
}
settings.writeSetting(SettingTag::licenseAccepted, true);
}

QSplashScreen *splash = 0;
int screenId = QApplication::desktop()->screenNumber();
splash = new QSplashScreen(QPixmap(QLatin1String("images/splash.png")));
if (QApplication::desktop()->isVirtualDesktop())
{
QRect srect(0, 0, splash->width(), splash->height());
splash->move(QApplication::desktop()->availableGeometry(screenId).center() - srect.center() );
}

auto args = arguments();
QString fileToLoad = mFileToLoad;
if (args.length() == 2)
{
fileToLoad = args[1];
}

mMainWindow = MainWindowFactory::getMainWindow(fileToLoad, settings);
mMainWindow->show();
return QApplication::exec();
}
9 changes: 7 additions & 2 deletions GuiApp/coreapplication.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@

#pragma once

#include "depthmapX/mainwindowfactory.h"
#include "version.h"
#include "settingsimpl.h"
#include <QApplication>
#include <QFileOpenEvent>
#include <QtDebug>
Expand All @@ -23,14 +26,13 @@ class CoreApplication : public QApplication
{
private:
QString mFileToLoad;
std::unique_ptr<MainWindow> mMainWindow;
public:
CoreApplication(int &argc, char **argv)
: QApplication(argc, argv)
{
}

const QString& fileToLoad() const { return mFileToLoad;}

bool event(QEvent *event)
{
// this event is triggered in macOS, either by calling "Open with..."
Expand All @@ -39,8 +41,11 @@ class CoreApplication : public QApplication
if (event->type() == QEvent::FileOpen) {
QFileOpenEvent *openEvent = static_cast<QFileOpenEvent *>(event);
mFileToLoad = openEvent->file();
mMainWindow->loadFile(openEvent->file());
}

return QApplication::event(event);
}

int exec();
};
Binary file added GuiApp/icons/graph.icns
Binary file not shown.
40 changes: 0 additions & 40 deletions GuiApp/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,9 @@

#include <QPixmap>
#include <QDir>
#include <QSplashScreen>
#include <QDesktopWidget>
#include <QDateTime>

#include "mainwindowfactory.h"
#include "coreapplication.h"
#include "version.h"
#include "settingsimpl.h"

#ifdef _WIN32
#include <windows.h>
Expand All @@ -40,40 +35,5 @@ int main(int argc, char *argv[])

CoreApplication app(argc, argv);

SettingsImpl settings(new DefaultSettingsFactory);

if (!settings.readSetting(SettingTag::licenseAccepted, false).toBool())
{
auto dummy = MainWindowFactory::getLicenseDialog();
dummy->setModal(true);
dummy->setWindowTitle(TITLE_BASE);
dummy->exec();
if ( dummy->result() == QDialog::Rejected) {
return 0;
}
settings.writeSetting(SettingTag::licenseAccepted, true);
}

QSplashScreen *splash = 0;
int screenId = QApplication::desktop()->screenNumber();
splash = new QSplashScreen(QPixmap(QLatin1String("images/splash.png")));
if (QApplication::desktop()->isVirtualDesktop())
{
QRect srect(0, 0, splash->width(), splash->height());
splash->move(QApplication::desktop()->availableGeometry(screenId).center() - srect.center() );
}
//splash->show();

auto args = app.arguments();
QString fileToLoad = app.fileToLoad();
if (args.length() == 2)
{
fileToLoad = args[1];
}

auto mainWindow = MainWindowFactory::getMainWindow(fileToLoad, settings);
mainWindow->show();

//splash->finish(&mainWin);
return app.exec();
}
33 changes: 33 additions & 0 deletions GuiApp/resources/Info.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?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>NSPrincipalClass</key>
<string>NSApplication</string>
<key>CFBundleIconFile</key>
<string>depthmapX.icns</string>
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleExecutable</key>
<string>depthmapX</string>
<key>CFBundleIdentifier</key>
<string>com.spacegroupucl.depthmapX</string>
<key>CFBundleDocumentTypes</key>
<array>
<dict>
<key>CFBundleTypeExtensions</key>
<array>
<string>graph</string>
</array>
<key>CFBundleTypeName</key>
<string>Graph File</string>
<key>CFBundleTypeRole</key>
<string>Editor</string>
<key>CFBundleTypeIconFile</key>
<string>graph.icns</string>
</dict>
</array>
</dict>
</plist>
61 changes: 25 additions & 36 deletions depthmapX/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,23 +107,7 @@ MainWindow::MainWindow(const QString &fileToLoad, Settings &settings) : mSetting

if (fileToLoad.length()>0)
{
MapView *child = createMapView();

QByteArray ba = fileToLoad.toUtf8(); // quick fix for weird chars (russian filename bug report)
char *file = ba.data(); // quick fix for weird chars (russian filename bug report)
if(child->getGraphDoc()->OnOpenDocument(file)) // quick fix for weird chars (russian filename bug report)
{
child->setCurrentFile(fileToLoad);
child->postLoadFile();
statusBar()->showMessage(tr("File loaded"), 2000);
child->show();
OnFocusGraph(child->getGraphDoc(), QGraphDoc::CONTROLS_LOADALL);
setCurrentFile(fileToLoad);
} else {
child->close();
QMessageBox::warning(this, "Failed to load", QString("Failed to load file ")+fileToLoad, QMessageBox::Ok, QMessageBox::Ok );
}

loadFile(fileToLoad);
}
}

Expand Down Expand Up @@ -181,6 +165,29 @@ void MainWindow::OnFileNew()
OnFocusGraph(child->getGraphDoc(), QGraphDoc::CONTROLS_LOADALL);
}

void MainWindow::loadFile(QString fileName) {
QMdiSubWindow *existing = findMapView(fileName);
if (existing) {
mdiArea->setActiveSubWindow(existing);
return;
}
MapView *child = createMapView();
QByteArray ba = fileName.toUtf8(); // quick fix for weird chars (russian filename bug report)
char *file = ba.data(); // quick fix for weird chars (russian filename bug report)
if(child->getGraphDoc()->OnOpenDocument(file)) // quick fix for weird chars (russian filename bug report)
{
child->setCurrentFile(fileName);
child->postLoadFile();
statusBar()->showMessage(tr("File loaded"), 2000);
child->show();
OnFocusGraph(child->getGraphDoc(), QGraphDoc::CONTROLS_LOADALL);
setCurrentFile(fileName);
} else {
child->close();
QMessageBox::warning(this, "Failed to load", QString("Failed to load file ")+fileName, QMessageBox::Ok, QMessageBox::Ok );
}
}

void MainWindow::OnFileOpen()
{
QString template_string;
Expand All @@ -195,25 +202,7 @@ void MainWindow::OnFileOpen()
&selectedFilter,
options);
if (!fileName.isEmpty()) {
QMdiSubWindow *existing = findMapView(fileName);
if (existing) {
mdiArea->setActiveSubWindow(existing);
return;
}
MapView *child = createMapView();
QByteArray ba = fileName.toUtf8(); // quick fix for weird chars (russian filename bug report)
char *file = ba.data(); // quick fix for weird chars (russian filename bug report)
if(child->getGraphDoc()->OnOpenDocument(file)) // quick fix for weird chars (russian filename bug report)
{
child->setCurrentFile(fileName);
child->postLoadFile();
statusBar()->showMessage(tr("File loaded"), 2000);
child->show();
OnFocusGraph(child->getGraphDoc(), QGraphDoc::CONTROLS_LOADALL);
setCurrentFile(fileName);
} else {
child->close();
}
loadFile(fileName);
}
}

Expand Down
1 change: 1 addition & 0 deletions depthmapX/mainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ class MainWindow : public QMainWindow
void showContextMenu(QPoint &point);
void UpdateStatus(QString s1, QString s2, QString s3);
void updateGLWindows(bool datasetChanged, bool recentreView);
void loadFile(QString fileName);

protected:
QGraphDoc* m_treeDoc;
Expand Down
4 changes: 2 additions & 2 deletions depthmapX/mainwindowfactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@
#include <memory>

namespace MainWindowFactory{
std::unique_ptr<QMainWindow> getMainWindow(const QString& fileToLoad, Settings &settings)
std::unique_ptr<MainWindow> getMainWindow(const QString& fileToLoad, Settings &settings)
{
return std::unique_ptr<QMainWindow>(new MainWindow(fileToLoad, settings));
return std::unique_ptr<MainWindow>(new MainWindow(fileToLoad, settings));
}

std::unique_ptr<QDialog> getLicenseDialog()
Expand Down
4 changes: 2 additions & 2 deletions depthmapX/mainwindowfactory.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@
#ifndef MAINWINDOWFACTORY_H
#define MAINWINDOWFACTORY_H

#include <QMainWindow>
#include <mainwindow.h>
#include <QDialog>
#include <memory>

class Settings;

namespace MainWindowFactory{
std::unique_ptr<QMainWindow> getMainWindow(const QString &fileToLoad, Settings &settings);
std::unique_ptr<MainWindow> getMainWindow(const QString &fileToLoad, Settings &settings);
std::unique_ptr<QDialog> getLicenseDialog();
}
#endif // MAINWINDOWFACTORY_H

0 comments on commit a1c7a8e

Please sign in to comment.