root/trunk/gui/src/main.cpp @ 458

Revision 458, 10.3 KB (checked in by wolke, 5 years ago)

applied hydrogen-svn20080901-Qt-translation.patch from guido scholz (thx)

Line 
1/*
2 * Hydrogen
3 * Copyright(c) 2002-2008 by Alex >Comix< Cominu [comix@users.sourceforge.net]
4 *
5 * http://www.hydrogen-music.org
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY, without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
20 *
21 */
22
23#include <QtGui>
24#include <QLibraryInfo>
25#include "config.h"
26#include "version.h"
27#include <getopt.h>
28
29#include "SplashScreen.h"
30#include "HydrogenApp.h"
31#include "MainForm.h"
32
33#ifdef LASH_SUPPORT
34#include <hydrogen/LashClient.h>
35#endif
36
37#include <hydrogen/midiMap.h>
38#include <hydrogen/audio_engine.h>
39#include <hydrogen/hydrogen.h>
40#include <hydrogen/globals.h>
41#include <hydrogen/event_queue.h>
42#include <hydrogen/Preferences.h>
43#include <hydrogen/data_path.h>
44#include <hydrogen/h2_exception.h>
45
46
47#include <iostream>
48using namespace std;
49
50void showInfo();
51void showUsage();
52
53
54#define HAS_ARG 1
55static struct option long_opts[] = {
56        {"driver", HAS_ARG, NULL, 'd'},
57        {"song", HAS_ARG, NULL, 's'},
58        {"version", 0, NULL, 'v'},
59        {"nosplash", 0, NULL, 'n'},
60        {"verbose", 0, NULL, 'V'},
61        {"help", 0, NULL, 'h'},
62        {0, 0, 0, 0},
63};
64
65#define NELEM(a) ( sizeof(a)/sizeof((a)[0]) )
66
67
68//
69// Set the palette used in the application
70//
71void setPalette( QApplication *pQApp )
72{
73        // create the default palette
74        QPalette defaultPalette;
75
76        // A general background color.
77        defaultPalette.setColor( QPalette::Background, QColor( 58, 62, 72 ) );
78
79        // A general foreground color.
80        defaultPalette.setColor( QPalette::Foreground, QColor( 255, 255, 255 ) );
81
82        // Used as the background color for text entry widgets; usually white or another light color.
83        defaultPalette.setColor( QPalette::Base, QColor( 88, 94, 112 ) );
84
85        // Used as the alternate background color in views with alternating row colors
86        defaultPalette.setColor( QPalette::AlternateBase, QColor( 138, 144, 162 ) );
87
88        // The foreground color used with Base. This is usually the same as the Foreground, in which case it must provide good contrast with Background and Base.
89        defaultPalette.setColor( QPalette::Text, QColor( 255, 255, 255 ) );
90
91        // The general button background color. This background can be different from Background as some styles require a different background color for buttons.
92        defaultPalette.setColor( QPalette::Button, QColor( 88, 94, 112 ) );
93
94        // A foreground color used with the Button color.
95        defaultPalette.setColor( QPalette::ButtonText, QColor( 255, 255, 255 ) );
96
97
98        // Lighter than Button color.
99        defaultPalette.setColor( QPalette::Light, QColor( 138, 144, 162 ) );
100
101        // Between Button and Light.
102        defaultPalette.setColor( QPalette::Midlight, QColor( 128, 134, 152 ) );
103
104        // Darker than Button.
105        defaultPalette.setColor( QPalette::Dark, QColor( 58, 62, 72 ) );
106
107        // Between Button and Dark.
108        defaultPalette.setColor( QPalette::Mid, QColor( 81, 86, 99 ) );
109
110        // A very dark color. By default, the shadow color is Qt::black.
111        defaultPalette.setColor( QPalette::Shadow, QColor( 255, 255, 255 ) );
112
113
114        // A color to indicate a selected item or the current item.
115        defaultPalette.setColor( QPalette::Highlight, QColor( 116, 124, 149 ) );
116
117        // A text color that contrasts with Highlight.
118        defaultPalette.setColor( QPalette::HighlightedText, QColor( 255, 255, 255 ) );
119
120        pQApp->setPalette( defaultPalette );
121}
122
123
124
125
126int main(int argc, char *argv[])
127{
128        try {
129
130                QString songFilename = "";
131                bool bNoSplash = false;
132                QString sSelectedDriver = "";
133
134#ifdef CONFIG_DEBUG
135                Object::use_verbose_log( true );
136#endif
137
138
139
140                // Options...
141                char *cp;
142                struct option *op;
143                char opts[NELEM(long_opts) * 2 + 1];
144
145                // Build up the short option QString
146                cp = opts;
147                for (op = long_opts; op < &long_opts[NELEM(long_opts)]; op++) {
148                        *cp++ = op->val;
149                        if (op->has_arg)
150                                *cp++ = ':';
151                }
152
153                QApplication* pQApp = new QApplication(argc, argv);
154
155                // Deal with the options
156                int c;
157                for (;;) {
158                        c = getopt_long(argc, argv, opts, long_opts, NULL);
159                        if (c == -1)
160                                break;
161
162                        switch(c) {
163                                case 'd':
164                                        sSelectedDriver = optarg;
165                                        break;
166
167                                case 's':
168                                        songFilename = optarg;
169                                        break;
170
171                                case 'v':
172                                        std::cout << get_version() << std::endl;
173                                        exit(0);
174                                        break;
175
176                                case 'V':
177                                        Object::use_verbose_log( true );
178                                        break;
179
180                                case 'n':
181                                        bNoSplash = true;
182                                        break;
183
184                                case 'h':
185                                case '?':
186                                        showInfo();
187                                        showUsage();
188                                        exit(0);
189                                        break;
190                        }
191                }
192
193                showInfo();
194
195                _INFOLOG( QString("Using QT version ") + QString( qVersion() ) );
196                _INFOLOG( "Using data path: " + H2Core::DataPath::get_data_path() );
197
198                H2Core::Preferences *pPref = H2Core::Preferences::getInstance();
199
200#ifdef LASH_SUPPORT
201
202        LashClient *lashClient = new LashClient("hydrogen", "Hydrogen", &argc, &argv);
203
204#endif
205                if (sSelectedDriver == "auto") {
206                        pPref->m_sAudioDriver = "Auto";
207                }
208                else if (sSelectedDriver == "jack") {
209                        pPref->m_sAudioDriver = "Jack";
210                }
211                else if ( sSelectedDriver == "oss" ) {
212                        pPref->m_sAudioDriver = "Oss";
213                }
214                else if ( sSelectedDriver == "alsa" ) {
215                        pPref->m_sAudioDriver = "Alsa";
216                }
217
218                QString family = pPref->getApplicationFontFamily();
219                pQApp->setFont( QFont( family, pPref->getApplicationFontPointSize() ) );
220
221                QTranslator qttor( 0 );
222                QTranslator tor( 0 );
223                QString sTranslationFile = QString("hydrogen.") + QLocale::system().name();
224                QString sLocale = QLocale::system().name();
225                if ( sLocale != "C") {
226                        if (qttor.load( QString( "qt_" ) + sLocale,
227                                QLibraryInfo::location(QLibraryInfo::TranslationsPath)))
228                                pQApp->installTranslator( &qttor );
229                        else
230                                _INFOLOG( QString("Warning: No Qt translation for locale %1 found.").arg(QLocale::system().name()));
231
232
233                        QString sTranslationPath = "data/i18n";
234                        QString total = sTranslationPath + "/" + sTranslationFile + ".qm";
235
236                        bool bTransOk = tor.load( total, "." );
237                        if ( bTransOk ) {
238                                _INFOLOG( QString( "Using locale: %1/%2" ).arg( sTranslationPath ).arg( sTranslationFile ) );
239                        }
240                        else {
241                                sTranslationPath = H2Core::DataPath::get_data_path() + "/i18n";
242                                total = sTranslationPath + "/" + sTranslationFile + ".qm";
243                                bTransOk = tor.load( total, "." );
244                                if (bTransOk) {
245                                        _INFOLOG( "Using locale: " + sTranslationPath + "/" + sTranslationFile );
246                                }
247                                else {
248                                        _INFOLOG( "Warning: no locale found: " + sTranslationPath + "/" + sTranslationFile );
249                                }
250                        }
251                        if (tor.isEmpty()) {
252                                _INFOLOG( "Warning: error loading locale: " +  total );
253                        }
254                }
255                pQApp->installTranslator( &tor );
256
257                QString sStyle = pPref->getQTStyle();
258                if (sStyle != "" ) {
259                        pQApp->setStyle( sStyle );
260                }
261
262                setPalette( pQApp );
263
264                SplashScreen *pSplash = new SplashScreen();
265
266                if (bNoSplash) {
267                        pSplash->hide();
268                }
269                else {
270                        pSplash->show();
271                }
272
273#ifdef LASH_SUPPORT
274        if ( H2Core::Preferences::getInstance()->useLash() ){   
275                if (lashClient->isConnected())
276                {
277                        lash_event_t* lash_event = lashClient->getNextEvent();
278                        if (lash_event && lash_event_get_type(lash_event) == LASH_Restore_File)
279                        {
280                                // notify client that this project was not a new one
281                                lashClient->setNewProject(false);
282                               
283                                songFilename = "";
284                                songFilename.append(lash_event_get_string(lash_event));
285                                songFilename.append("/hydrogen.h2song");
286                               
287//                              Logger::getInstance()->log("[LASH] Restore file: " + songFilename);
288       
289                                lash_event_destroy(lash_event);
290                        }
291                        else if (lash_event)
292                        {
293//                              Logger::getInstance()->log("[LASH] ERROR: Instead of restore file got event: " + lash_event_get_type(lash_event));
294                                lash_event_destroy(lash_event);
295                        }
296                }
297        }       
298#endif
299
300               
301                MainForm *pMainForm = new MainForm( pQApp, songFilename );
302                pMainForm->show();
303                pSplash->finish( pMainForm );
304
305                pQApp->exec();
306
307                delete pSplash;
308                delete pMainForm;
309                delete pQApp;
310                delete pPref;
311                delete H2Core::EventQueue::get_instance();
312                delete H2Core::AudioEngine::get_instance();
313
314                delete MidiMap::getInstance();
315                delete ActionManager::getInstance();
316
317                _INFOLOG( "Quitting..." );
318                cout << "\nBye..." << endl;
319                delete Logger::get_instance();
320
321                int nObj = Object::get_objects_number();
322                if (nObj != 0) {
323                        std::cerr << "\n\n\n " << to_string( nObj ).toStdString() << " alive objects\n\n" << std::endl << std::endl;
324                        Object::print_object_map();
325                }
326
327                //      pQApp->dumpObjectTree();
328
329        }
330        catch ( const H2Core::H2Exception& ex ) {
331                std::cerr << "[main] Exception: " << ex.what() << std::endl;
332        }
333        catch (...) {
334                std::cerr << "[main] Unknown exception X-(" << std::endl;
335        }
336
337        return 0;
338}
339
340
341
342/**
343 * Show some information
344 */
345void showInfo()
346{
347        cout << "\nHydrogen " + get_version() + " [" + __DATE__ + "]  [http://www.hydrogen-music.org]" << endl;
348        cout << "Copyright 2002-2008 Alessandro Cominu" << endl;
349//      _INFOLOG( "Compiled modules: " + QString(COMPILED_FEATURES) << endl;
350
351        if ( Object::is_using_verbose_log() ) {
352                cout << "\nVerbose log mode = active" << endl;
353        }
354
355        cout << "\nHydrogen comes with ABSOLUTELY NO WARRANTY" << endl;
356        cout << "This is free software, and you are welcome to redistribute it" << endl;
357        cout << "under certain conditions. See the file COPYING for details\n" << endl;
358}
359
360
361
362/**
363 * Show the correct usage
364 */
365void showUsage()
366{
367        std::cout << "Usage: hydrogen [-v] [-h] -s file" << std::endl;
368        std::cout << "   -d, --driver AUDIODRIVER - Use the selected audio driver (jack, alsa, oss)" << std::endl;
369        std::cout << "   -s, --song FILE - Load a song (*.h2song) at startup" << std::endl;
370#ifdef LASH_SUPPORT
371        std::cout << "   --lash-no-start-server - If LASH server not running, don't start" << endl
372                  << "                            it (LASH 0.5.3 and later)." << std::endl;
373        std::cout << "   --lash-no-autoresume - Tell LASH server not to assume I'm returning" << std::endl
374                  << "                          from a crash." << std::endl;
375#endif
376        std::cout << "   -n, --nosplash - Hide splash screen" << std::endl;
377        std::cout << "   -V, --verbose - Print a lot of debugging info" << std::endl;
378        std::cout << "   -v, --version - Show version info" << std::endl;
379        std::cout << "   -h, --help - Show this help message" << std::endl;
380}
Note: See TracBrowser for help on using the browser.