-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathGrindstone.cpp
More file actions
148 lines (121 loc) · 4.56 KB
/
Grindstone.cpp
File metadata and controls
148 lines (121 loc) · 4.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
*
* Copyright 2013, Dominik Schmidt <domme@tomahawk-player.org>
*
* Tomahawk 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.
*
* Tomahawk 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 Tomahawk. If not, see <http://www.gnu.org/licenses/>.
*/
#include "Grindstone.h"
#include "ResolverDialog.h"
#include <accounts/AccountConfigWidget.h>
#include <jobview/JobStatusView.h>
#include <jobview/JobStatusModel.h>
#include <resolvers/JSResolver.h>
#include <utils/Logger.h>
#include <Pipeline.h>
#include <QDebug>
#include <QSettings>
#include <QMainWindow>
#include <QStringList>
#include <QApplication>
Grindstone::Grindstone(int& argc, char* argv[])
: QApplication( argc, argv )
, m_mainWindow( new QMainWindow() )
{
if( arguments().count() < 2 )
{
qDebug() << "Too few arguments passed";
exit(-1);
}
// init settings
QSettings settings;
// preset environment that is overwritten by --env if set
QString environment = settings.value("defaultEnvironment", "default").toString();
bool showConfig = false;
// parse --env argument
QStringList arguments = QCoreApplication::instance()->arguments();
arguments.takeFirst();
for( int i=0; i<arguments.count(); i++ )
{
const QString arg = arguments[i];
if( arg == "--env" && (i+1)<arguments.count() )
{
arguments.removeAt( i );
environment = arguments.takeAt( i );
}
if( arg == "--config" )
{
arguments.removeAt( i );
showConfig = true;
}
}
// tell the user what env is used now
qDebug() << "Running in Environment:" << environment;
// load tomahawkjsPath from settings file
settings.beginGroup( QString( "env_%1" ).arg( environment ) );
QString tomahawkjsPath = settings.value( "tomahawkjsPath" ).toString();
settings.endGroup();
// add the tomahawkksPath to the JSResolver arguments
if( tomahawkjsPath.isNull() )
{
qDebug() << "**********************************************************************";
qDebug() << "No default tomahawk.js in this env.";
qDebug() << "Make sure it's passed as additional path to Grindstone!";
qDebug() << "You can add a default one by adding";
qDebug() << "";
qDebug() << QString("[env_%1]"
"\ntomahawkjsPath=/home/haxX0r/pathToYour/tomahawk.js"
).arg( environment );
qDebug() << "";
qDebug() << "to your Grindstone.conf";
qDebug() << "**********************************************************************";
}
else
{
qDebug() << "Found default tomahawkjs for this env: " << tomahawkjsPath;
arguments << tomahawkjsPath;
}
//HACK: this really shouldn't be coupled so badly, you shouldn't need to init the job view just to use JSresolver
JobStatusView* jobsView = new JobStatusView( 0 );
JobStatusModel* sourceModel = new JobStatusModel( jobsView );
JobStatusSortModel* jobsModel = new JobStatusSortModel( jobsView );
jobsModel->setJobModel( sourceModel );
jobsView->setModel( jobsModel );
// poc: you're able to init this here - also we need it to start the resolver ...
new Tomahawk::Pipeline( 0 );
m_resolver = new JSResolver( uuid(), arguments.takeFirst(), arguments );
m_resolver->start();
if( !m_resolver->running() )
{
qDebug() << "Resolver not running, exiting.";
::exit( -1 );
}
if( showConfig )
{
tLog() << "Show config widget";
ResolverDialog* dialog = new ResolverDialog(m_resolver);
dialog->show();
connect(dialog, SIGNAL( accepted() ), SLOT( onConfigDialogAccepted() ) );
connect(dialog, SIGNAL(rejected() ), QCoreApplication::instance(), SLOT( quit() ) );
}
}
Grindstone::~Grindstone()
{
}
void
Grindstone::onConfigDialogAccepted()
{
m_resolver->saveConfig();
// wtf ... webkit needs some time to save the config ....
QTimer::singleShot( 2000, QCoreApplication::instance(), SLOT( quit() ) );
}