~ubuntu-branches/ubuntu/wily/smplayer/wily

« back to all changes in this revision

Viewing changes to .pc/handle_local_urls.diff/src/smplayer.cpp

  • Committer: Package Import Robot
  • Author(s): Maia Kozheva, Maia Kozheva, Alessio Treglia
  • Date: 2012-04-14 12:01:57 UTC
  • mfrom: (1.1.13)
  • mto: (20.2.1 sid)
  • mto: This revision was merged to the branch mainline in revision 23.
  • Revision ID: package-import@ubuntu.com-20120414120157-mndwobcslgisomso
[ Maia Kozheva ]
* New upstream release:
  - Changes since 0.7.1:
    + A toolbar editor has been added. Now it's possible to select the
      buttons and controls that want to appear in the toolbars.
    + New video filters: gradfun, blur and sharpen.
    + Now it's possible to change the GUI (default, mini, mpc) at runtime,
      no restart required.
    + sub files from opensubtitles should work again.
    + (Youtube) Recognize short urls (like this one:
      http://y2u.be/F5OcZBVPwOA)
    + Better support for chapters in video files.
    + Bug fix: remote m3u files work from the favorites menu or command line.
    + Internal changes in the single instance option (switch to 
      QtSingleApplication).
  - Fixes since 0.7.0:
    + SMPlayer took more than 10 seconds to show when running for the very
      first time.
    + The links to download subtitles from Opensubtitles were wrong.
    + SMPlayer crashed in the favorite editor when trying to select a file
      if the KDE open dialog was used.
  - Changes since 0.7.0:
    + By default the screenshots are saved in the user's pictures folder
      instead of the SMPlayer's config folder.
    + Now it's possible to change the opensubtitles server.
    + Youtube: seeking is slow with flv videos, so now flv videos have the
      lowest priority.
    + Youtube: now it's possible to search and download videos from youtube.
      This is provided by an external application (in linux you have to
      install an independent package: smtube).
* debian/copyright:
  - Rewrite according to DEP-5 specification.
* debian/control:
  - Depend on mplayer2 | mplayer. (Closes: #638279)
  - Update Standards-Version to 3.9.3.
* Remove debian/patches/handle_local_urls.diff, merged upstream.

[ Alessio Treglia ]
* Mention smplayer is also a front-end for MPlayer2.
* Fix small typo in the description.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*  smplayer, GUI front-end for mplayer.
2
 
    Copyright (C) 2006-2012 Ricardo Villalba <rvm@users.sourceforge.net>
3
 
 
4
 
    This program is free software; you can redistribute it and/or modify
5
 
    it under the terms of the GNU General Public License as published by
6
 
    the Free Software Foundation; either version 2 of the License, or
7
 
    (at your option) any later version.
8
 
 
9
 
    This program is distributed in the hope that it will be useful,
10
 
    but WITHOUT ANY WARRANTY; without even the implied warranty of
11
 
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
 
    GNU General Public License for more details.
13
 
 
14
 
    You should have received a copy of the GNU General Public License
15
 
    along with this program; if not, write to the Free Software
16
 
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
17
 
*/
18
 
 
19
 
#include "smplayer.h"
20
 
#include "defaultgui.h"
21
 
#include "minigui.h"
22
 
#include "mpcgui.h"
23
 
#include "global.h"
24
 
#include "paths.h"
25
 
#include "translator.h"
26
 
#include "version.h"
27
 
#include "config.h"
28
 
#include "myclient.h"
29
 
#include "clhelp.h"
30
 
 
31
 
#include <QDir>
32
 
#include <QApplication>
33
 
 
34
 
#include <stdio.h>
35
 
 
36
 
#ifdef Q_OS_WIN
37
 
#if USE_ASSOCIATIONS
38
 
#include "extensions.h"
39
 
#include "winfileassoc.h"       //required for Uninstall
40
 
#endif
41
 
#endif
42
 
 
43
 
 
44
 
using namespace Global;
45
 
 
46
 
SMPlayer::SMPlayer(const QString & config_path, QObject * parent )
47
 
        : QObject(parent) 
48
 
{
49
 
        main_window = 0;
50
 
        gui_to_use = "DefaultGui";
51
 
 
52
 
        close_at_end = -1; // Not set
53
 
        start_in_fullscreen = -1; // Not set
54
 
        use_control_server = true;
55
 
 
56
 
        move_gui = false;
57
 
        resize_gui = false;
58
 
 
59
 
    Paths::setAppPath( qApp->applicationDirPath() );
60
 
 
61
 
#ifndef PORTABLE_APP
62
 
        if (config_path.isEmpty()) createConfigDirectory();
63
 
#endif
64
 
        global_init(config_path);
65
 
 
66
 
        // Application translations
67
 
        translator->load( pref->language );
68
 
        showInfo();
69
 
}
70
 
 
71
 
SMPlayer::~SMPlayer() {
72
 
        if (main_window != 0) delete main_window;
73
 
        global_end();
74
 
}
75
 
 
76
 
BaseGui * SMPlayer::gui() {
77
 
        if (main_window == 0) {
78
 
                // Changes to app path, so smplayer can find a relative mplayer path
79
 
                QDir::setCurrent(Paths::appPath());
80
 
                qDebug("SMPlayer::gui: changed working directory to app path");
81
 
                qDebug("SMPlayer::gui: current directory: %s", QDir::currentPath().toUtf8().data());
82
 
                
83
 
                if (gui_to_use.toLower() == "minigui") 
84
 
                        main_window = new MiniGui(use_control_server, 0);
85
 
                else 
86
 
                if (gui_to_use.toLower() == "mpcgui")
87
 
                        main_window = new MpcGui(use_control_server, 0);
88
 
                else
89
 
                        main_window = new DefaultGui(use_control_server, 0);
90
 
 
91
 
                if (move_gui) {
92
 
                        qDebug("SMPlayer::gui: moving main window to %d %d", gui_position.x(), gui_position.y());
93
 
                        main_window->move(gui_position);
94
 
                }
95
 
                if (resize_gui) {
96
 
                        qDebug("SMPlayer::gui: resizing main window to %dx%d", gui_size.width(), gui_size.height());
97
 
                        main_window->resize(gui_size);
98
 
                }
99
 
 
100
 
                main_window->setForceCloseOnFinish(close_at_end);
101
 
                main_window->setForceStartInFullscreen(start_in_fullscreen);
102
 
        }
103
 
 
104
 
        return main_window;
105
 
}
106
 
 
107
 
SMPlayer::ExitCode SMPlayer::processArgs(QStringList args) {
108
 
        qDebug("SMPlayer::processArgs: arguments: %d", args.count());
109
 
        for (int n = 0; n < args.count(); n++) {
110
 
                qDebug("SMPlayer::processArgs: %d = %s", n, args[n].toUtf8().data());
111
 
        }
112
 
 
113
 
 
114
 
    QString action; // Action to be passed to running instance
115
 
        bool show_help = false;
116
 
 
117
 
        if (!pref->gui.isEmpty()) gui_to_use = pref->gui;
118
 
        bool add_to_playlist = false;
119
 
 
120
 
#ifdef Q_OS_WIN
121
 
        if (args.contains("-uninstall")){
122
 
#if USE_ASSOCIATIONS
123
 
                //Called by uninstaller. Will restore old associations.
124
 
                WinFileAssoc RegAssoc; 
125
 
                Extensions exts; 
126
 
                QStringList regExts; 
127
 
                RegAssoc.GetRegisteredExtensions(exts.multimedia(), regExts); 
128
 
                RegAssoc.RestoreFileAssociations(regExts); 
129
 
                printf("Restored associations\n");
130
 
#endif
131
 
                return NoError; 
132
 
        }
133
 
#endif
134
 
 
135
 
        for (int n = 1; n < args.count(); n++) {
136
 
                QString argument = args[n];
137
 
 
138
 
                if (argument == "-send-action") {
139
 
                        if (n+1 < args.count()) {
140
 
                                n++;
141
 
                                action = args[n];
142
 
                        } else {
143
 
                                printf("Error: expected parameter for -send-action\r\n");
144
 
                                return ErrorArgument;
145
 
                        }
146
 
                }
147
 
                else
148
 
                if (argument == "-actions") {
149
 
                        if (n+1 < args.count()) {
150
 
                                n++;
151
 
                                actions_list = args[n];
152
 
                        } else {
153
 
                                printf("Error: expected parameter for -actions\r\n");
154
 
                                return ErrorArgument;
155
 
                        }
156
 
                }
157
 
                else
158
 
                if (argument == "-sub") {
159
 
                        if (n+1 < args.count()) {
160
 
                                n++;
161
 
                                QString file = args[n];
162
 
                                if (QFile::exists(file)) {
163
 
                                        subtitle_file = QFileInfo(file).absoluteFilePath();
164
 
                                } else {
165
 
                                        printf("Error: file '%s' doesn't exists\r\n", file.toUtf8().constData());
166
 
                                }
167
 
                        } else {
168
 
                                printf("Error: expected parameter for -sub\r\n");
169
 
                                return ErrorArgument;
170
 
                        }
171
 
                }
172
 
                else
173
 
                if (argument == "-pos") {
174
 
                        if (n+2 < args.count()) {
175
 
                                bool ok_x, ok_y;
176
 
                                n++;
177
 
                                gui_position.setX( args[n].toInt(&ok_x) );
178
 
                                n++;
179
 
                                gui_position.setY( args[n].toInt(&ok_y) );
180
 
                                if (ok_x && ok_y) move_gui = true;
181
 
                        } else {
182
 
                                printf("Error: expected parameter for -pos\r\n");
183
 
                                return ErrorArgument;
184
 
                        }
185
 
                }
186
 
                else
187
 
                if (argument == "-size") {
188
 
                        if (n+2 < args.count()) {
189
 
                                bool ok_width, ok_height;
190
 
                                n++;
191
 
                                gui_size.setWidth( args[n].toInt(&ok_width) );
192
 
                                n++;
193
 
                                gui_size.setHeight( args[n].toInt(&ok_height) );
194
 
                                if (ok_width && ok_height) resize_gui = true;
195
 
                        } else {
196
 
                                printf("Error: expected parameter for -resize\r\n");
197
 
                                return ErrorArgument;
198
 
                        }
199
 
                }
200
 
                else
201
 
                if ((argument == "--help") || (argument == "-help") ||
202
 
            (argument == "-h") || (argument == "-?") ) 
203
 
                {
204
 
                        show_help = true;
205
 
                }
206
 
                else
207
 
                if (argument == "-close-at-end") {
208
 
                        close_at_end = 1;
209
 
                }
210
 
                else
211
 
                if (argument == "-no-close-at-end") {
212
 
                        close_at_end = 0;
213
 
                }
214
 
                else
215
 
                if (argument == "-fullscreen") {
216
 
                        start_in_fullscreen = 1;
217
 
                }
218
 
                else
219
 
                if (argument == "-no-fullscreen") {
220
 
                        start_in_fullscreen = 0;
221
 
                }
222
 
                else
223
 
                if (argument == "-disable-server") {
224
 
                        use_control_server = false;
225
 
                }
226
 
                else
227
 
                if (argument == "-add-to-playlist") {
228
 
                        add_to_playlist = true;
229
 
                }
230
 
                else
231
 
                if (argument == "-mini" || argument == "-minigui") {
232
 
                        gui_to_use = "MiniGui";
233
 
                }
234
 
                else
235
 
                if (argument == "-mpcgui") {
236
 
                        gui_to_use = "MpcGui";
237
 
                }
238
 
                else
239
 
                if (argument == "-defaultgui") {
240
 
                        gui_to_use = "DefaultGui";
241
 
                }
242
 
                else {
243
 
                        // File
244
 
                        if (QFile::exists( argument )) {
245
 
                                argument = QFileInfo(argument).absoluteFilePath();
246
 
                        }
247
 
                        files_to_play.append( argument );
248
 
                }
249
 
        }
250
 
 
251
 
        if (show_help) {
252
 
                printf("%s\n", CLHelp::help().toLocal8Bit().data());
253
 
                return NoError;
254
 
        }
255
 
 
256
 
        qDebug("SMPlayer::processArgs: files_to_play: count: %d", files_to_play.count() );
257
 
        for (int n=0; n < files_to_play.count(); n++) {
258
 
                qDebug("SMPlayer::processArgs: files_to_play[%d]: '%s'", n, files_to_play[n].toUtf8().data());
259
 
        }
260
 
 
261
 
 
262
 
        if (pref->use_single_instance) {
263
 
                // Single instance
264
 
                int port = pref->connection_port;
265
 
                if (pref->use_autoport) port = pref->autoport;
266
 
 
267
 
                MyClient *c = new MyClient(port);
268
 
                //c->setTimeOut(1000);
269
 
                qDebug("SMPlayer::processArgs: trying to connect to port %d", port);
270
 
 
271
 
                if (c->openConnection()) {
272
 
                        qDebug("SMPlayer::processArgs: found another instance");
273
 
 
274
 
                        if (!action.isEmpty()) {
275
 
                                if (c->sendAction(action)) {
276
 
                                        qDebug("SMPlayer::processArgs: action passed successfully to the running instance");
277
 
                                } else {
278
 
                                        printf("Error: action couldn't be passed to the running instance");
279
 
                                        return NoAction;
280
 
                                }
281
 
                        }
282
 
                        else {
283
 
                                if (!subtitle_file.isEmpty()) {
284
 
                                        if (c->sendSubtitleFile(subtitle_file)) {
285
 
                                                qDebug("SMPlayer::processArgs: subtitle file sent successfully to the running instance");
286
 
                                        } else {
287
 
                                                qDebug("SMPlayer::processArgs: subtitle file couldn't be sent to another instance");
288
 
                                        }
289
 
                                }
290
 
 
291
 
                                if (!files_to_play.isEmpty()) {
292
 
                                        if (c->sendFiles(files_to_play, add_to_playlist)) {
293
 
                                                qDebug("SMPlayer::processArgs: files sent successfully to the running instance");
294
 
                                qDebug("SMPlayer::processArgs: exiting.");
295
 
                                        } else {
296
 
                                                qDebug("SMPlayer::processArgs: files couldn't be sent to another instance");
297
 
                                        }
298
 
                                }
299
 
                        }
300
 
                        c->closeConnection();
301
 
                        return NoError;
302
 
                } else {
303
 
                        if (!action.isEmpty()) {
304
 
                                printf("Error: no running instance found\r\n");
305
 
                                return NoRunningInstance;
306
 
                        }
307
 
                }
308
 
        }
309
 
 
310
 
        if (!pref->default_font.isEmpty()) {
311
 
                QFont f;
312
 
                f.fromString(pref->default_font);
313
 
                qApp->setFont(f);
314
 
        }
315
 
 
316
 
        return SMPlayer::NoExit;
317
 
}
318
 
 
319
 
void SMPlayer::start() {
320
 
        if (!gui()->startHidden() || !files_to_play.isEmpty() ) gui()->show();
321
 
        if (!files_to_play.isEmpty()) {
322
 
                if (!subtitle_file.isEmpty()) gui()->setInitialSubtitle(subtitle_file);
323
 
                gui()->openFiles(files_to_play);
324
 
        }
325
 
 
326
 
        if (!actions_list.isEmpty()) {
327
 
                if (files_to_play.isEmpty()) {
328
 
                        gui()->runActions(actions_list);
329
 
                } else {
330
 
                        gui()->runActionsLater(actions_list);
331
 
                }
332
 
        }
333
 
}
334
 
 
335
 
#ifndef PORTABLE_APP
336
 
void SMPlayer::createConfigDirectory() {
337
 
        // Create smplayer config directory
338
 
        if (!QFile::exists(Paths::configPath())) {
339
 
                QDir d;
340
 
                if (!d.mkdir(Paths::configPath())) {
341
 
                        qWarning("SMPlayer::createConfigDirectory: can't create %s", Paths::configPath().toUtf8().data());
342
 
                }
343
 
                QString s = Paths::configPath() + "/screenshots";
344
 
                if (!d.mkdir(s)) {
345
 
                        qWarning("SMPlayer::createHomeDirectory: can't create %s", s.toUtf8().data());
346
 
                }
347
 
        }
348
 
}
349
 
#endif
350
 
 
351
 
void SMPlayer::showInfo() {
352
 
#ifdef Q_OS_WIN
353
 
        QString win_ver;
354
 
        switch (QSysInfo::WindowsVersion) {
355
 
                case QSysInfo::WV_32s: win_ver = "Windows 3.1"; break;
356
 
                case QSysInfo::WV_95: win_ver = "Windows 95"; break;
357
 
                case QSysInfo::WV_98: win_ver = "Windows 98"; break;
358
 
                case QSysInfo::WV_Me: win_ver = "Windows Me"; break;
359
 
                case QSysInfo::WV_NT: win_ver = "Windows NT"; break;
360
 
                case QSysInfo::WV_2000: win_ver = "Windows 2000"; break;
361
 
                case QSysInfo::WV_XP: win_ver = "Windows XP"; break;
362
 
                case QSysInfo::WV_2003: win_ver = "Windows Server 2003"; break;
363
 
                case QSysInfo::WV_VISTA: win_ver = "Windows Vista"; break;
364
 
                #if QT_VERSION >= 0x040501
365
 
                case QSysInfo::WV_WINDOWS7: win_ver = "Windows 7"; break;
366
 
                #endif
367
 
                default: win_ver = QString("other: %1").arg(QSysInfo::WindowsVersion);
368
 
        }
369
 
#endif
370
 
        QString s = QObject::tr("This is SMPlayer v. %1 running on %2")
371
 
            .arg(smplayerVersion())
372
 
#ifdef Q_OS_LINUX
373
 
           .arg("Linux")
374
 
#else
375
 
#ifdef Q_OS_WIN
376
 
           .arg("Windows ("+win_ver+")")
377
 
#else
378
 
#ifdef Q_OS_OS2
379
 
           .arg("eCS (OS/2)")
380
 
#else
381
 
                   .arg("Other OS")
382
 
#endif
383
 
#endif
384
 
#endif
385
 
           ;
386
 
 
387
 
        printf("%s\n", s.toLocal8Bit().data() );
388
 
        qDebug("%s", s.toUtf8().data() );
389
 
        qDebug("Compiled with Qt v. %s, using %s", QT_VERSION_STR, qVersion());
390
 
 
391
 
        qDebug(" * application path: '%s'", Paths::appPath().toUtf8().data());
392
 
        qDebug(" * data path: '%s'", Paths::dataPath().toUtf8().data());
393
 
        qDebug(" * translation path: '%s'", Paths::translationPath().toUtf8().data());
394
 
        qDebug(" * doc path: '%s'", Paths::docPath().toUtf8().data());
395
 
        qDebug(" * themes path: '%s'", Paths::themesPath().toUtf8().data());
396
 
        qDebug(" * shortcuts path: '%s'", Paths::shortcutsPath().toUtf8().data());
397
 
        qDebug(" * config path: '%s'", Paths::configPath().toUtf8().data());
398
 
        qDebug(" * ini path: '%s'", Paths::iniPath().toUtf8().data());
399
 
        qDebug(" * file for subtitles' styles: '%s'", Paths::subtitleStyleFile().toUtf8().data());
400
 
        qDebug(" * current path: '%s'", QDir::currentPath().toUtf8().data());
401
 
}