Entropy Piano Tuner  1.1.3 (documentation not yet complete)
An open-source experimental software for piano tuning by entropy minimization
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
platformtools.cpp
Go to the documentation of this file.
1 /*****************************************************************************
2  * Copyright 2015 Haye Hinrichsen, Christoph Wick
3  *
4  * This file is part of Entropy Piano Tuner.
5  *
6  * Entropy Piano Tuner is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by the
8  * Free Software Foundation, either version 3 of the License, or (at your
9  * option) any later version.
10  *
11  * Entropy Piano Tuner is distributed in the hope that it will be useful, but
12  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13  * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14  * more details.
15  *
16  * You should have received a copy of the GNU General Public License along with
17  * Entropy Piano Tuner. If not, see http://www.gnu.org/licenses/.
18  *****************************************************************************/
19 
20 #include "platformtools.h"
21 #include <QFileInfo>
22 #include <QDir>
23 #include <QStandardPaths>
24 #include <QDebug>
25 
26 #include "tunerapplication.h"
27 
28 bool PlatformTools::loadStartupFile(const QStringList args) {
29  return openFileFromArgs(args);
30 }
31 
32 bool PlatformTools::openFileFromArgs(const QStringList &args) {
33  QString startupFile;
34  bool cached = false;
35 
36  // get startup file from the arguments
37  if (args.size() > 1) {
38  // first argument is program name, second is path to file, maybe with whitespaces so combine all
39  QStringList pathParts(args);
40  pathParts.pop_front(); // program name
41  startupFile = pathParts.join(" ");
42  // search for ' ' that should keep the filename together
43  startupFile = startupFile.left(startupFile.lastIndexOf("'"));
44  startupFile = startupFile.right(startupFile.length() - startupFile.indexOf("'") - 1);
45  QFileInfo f(startupFile);
46  if (f.fileName() == startupFile) {
47  // search in documents folder by default
48  QDir docDir(QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation));
49  startupFile = docDir.absoluteFilePath(f.fileName());
50  }
51  }
52  if (startupFile.isEmpty()) {
53  // empty file cannot be opened
54  return false;
55  }
56  return TunerApplication::getSingleton().openFile(startupFile, cached);
57 }
58 
59 void PlatformTools::openFile(const char *file, bool cached) {
60  QString fileName(file);
61  LogI("Opening external file %s", file);
62  QMetaObject::invokeMethod(TunerApplication::getSingletonPtr(),
63  "openFile",
64  Qt::QueuedConnection,
65  QGenericReturnArgument(0),
66  Q_ARG(QString, fileName),
67  Q_ARG(bool, cached));
68 }
bool openFile(QString filePath, bool cached)
Open the given file.
void openFile(const char *file, bool cached)
Function called from the implementations to open a file.
static TunerApplication & getSingleton()
Getter for the singleton instance.
static TunerApplication * getSingletonPtr()
Getter for the singleton instance.
virtual bool loadStartupFile(const QStringList args)
Load a startup file from the given arguments.
#define LogI(...)
Definition: log.h:50
virtual bool openFileFromArgs(const QStringList &args)
open the startup file from the arguments