]> git.tdb.fi Git - xinema.git/blob - source/xinema.cpp
Move the language select buttons to the bottom of the page
[xinema.git] / source / xinema.cpp
1 #include <sigc++/bind.h>
2 #include <msp/fs/dir.h>
3 #include <msp/graphics/display_private.h>
4 #include <msp/time/utils.h>
5 #include "xineengine.h"
6 #include "xinema.h"
7 #include "xinestream.h"
8
9 using namespace std;
10 using namespace Msp;
11
12 Xinema::EarlyInit::EarlyInit()
13 {
14         XInitThreads();
15 }
16
17
18 Xinema::Xinema(int, char **):
19         window(display, 1920, 1080),
20         network(*this),
21         engine(0),
22         stream(0),
23         logo_mode(false),
24         pending_logo(false)
25 {
26         window.signal_close.connect(sigc::bind(sigc::mem_fun(this, &Xinema::exit), 0));
27 }
28
29 int Xinema::main()
30 {
31         window.show();
32         display.tick();
33
34         engine = new XineEngine(window);
35         show_logo();
36
37         Application::main();
38
39         if(stream)
40                 delete stream;
41         delete engine;
42
43         return exit_code;
44 }
45
46 void Xinema::tick()
47 {
48         string mrl;
49         bool logo;
50         {
51                 MutexLock lock(command_mutex);
52                 mrl = pending_mrl;
53                 logo = pending_logo;
54                 pending_mrl.clear();
55                 pending_logo = false;
56         }
57
58         if(!mrl.empty())
59         {
60                 bool had_stream = stream;
61
62                 delete stream;
63                 stream = 0;
64
65                 if(had_stream && !logo_mode)
66                         signal_stream_destroyed.emit();
67
68                 logo_mode = logo;
69                 stream = new XineStream(*engine, mrl);
70                 if(!logo_mode)
71                         stream->signal_finished.connect(sigc::mem_fun(this, &Xinema::show_logo));
72                 stream->play();
73
74                 if(!logo_mode)
75                         signal_stream_created.emit(*stream);
76         }
77
78         XLockDisplay(display.get_private().display);
79         display.tick();
80         XUnlockDisplay(display.get_private().display);
81
82         engine->tick();
83
84         Time::sleep(10*Time::msec);
85 }
86
87 void Xinema::play_file(const FS::Path &fn)
88 {
89         MutexLock lock(command_mutex);
90         pending_mrl = "file://"+fn.str();
91         pending_logo = false;
92 }
93
94 void Xinema::show_logo()
95 {
96         MutexLock lock(command_mutex);
97         pending_mrl = "file://"+(FS::get_sys_data_dir()/"xinema.png").str();
98         pending_logo = true;
99 }