Basics of a tray-iconned GUI server.
[dcpomatic.git] / src / tools / servomatic_gui.cc
1 /*
2     Copyright (C) 2012 Carl Hetherington <cth@carlh.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., 675 Mass Ave, Cambridge, MA 02139, USA.
17
18 */
19
20 #include <boost/thread.hpp>
21 #include <wx/taskbar.h>
22 #include <wx/icon.h>
23 #include "wx_util.h"
24 #include "lib/util.h"
25 #include "lib/server.h"
26
27 using namespace boost;
28
29 enum {
30         ID_status = 1,
31         ID_quit
32 };
33
34 class StatusDialog : public wxDialog
35 {
36 public:
37         StatusDialog ()
38                 : wxDialog (0, wxID_ANY, _("DVD-o-matic encode server"), wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE)
39         {
40                 wxFlexGridSizer* table = new wxFlexGridSizer (2, 6, 6);
41                 table->AddGrowableCol (1, 1);
42
43                 add_label_to_sizer (table, this, "Hello");
44
45                 SetSizer (table);
46                 table->Layout ();
47                 table->SetSizeHints (this);
48         }
49 };
50
51 class TaskBarIcon : public wxTaskBarIcon
52 {
53 public:
54         TaskBarIcon ()
55         {
56                 wxIcon icon (std_to_wx ("taskbar_icon"));
57                 SetIcon (icon, std_to_wx ("DVD-o-matic encode server"));
58
59                 Connect (ID_status, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler (TaskBarIcon::status));
60                 Connect (ID_quit, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler (TaskBarIcon::quit));
61         }
62         
63         wxMenu* CreatePopupMenu ()
64         {
65                 wxMenu* menu = new wxMenu;
66                 menu->Append (ID_status, std_to_wx ("Status..."));
67                 menu->Append (ID_quit, std_to_wx ("Quit"));
68                 return menu;
69         }
70
71 private:
72         void status (wxCommandEvent &)
73         {
74                 StatusDialog* d = new StatusDialog;
75                 d->Show ();
76         }
77
78         void quit (wxCommandEvent &)
79         {
80                 wxTheApp->ExitMainLoop ();
81         }
82 };
83
84 class App : public wxApp
85 {
86 public:
87         App ()
88                 : wxApp ()
89                 , _thread (0)
90         {}
91
92 private:        
93         
94         bool OnInit ()
95         {
96                 dvdomatic_setup ();
97
98                 new TaskBarIcon;
99
100                 _thread = new thread (bind (&App::main_thread, this));
101                 return true;
102         }
103
104         void main_thread ()
105         {
106                 Server server;
107                 server.run ();
108         }
109
110         boost::thread* _thread;
111 };
112
113 IMPLEMENT_APP (App)