2 Copyright (C) 2012 Carl Hetherington <cth@carlh.net>
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.
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.
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.
20 #include <boost/thread.hpp>
21 #include <wx/taskbar.h>
25 #include "lib/server.h"
26 #include "lib/config.h"
30 using boost::shared_ptr;
40 class MemoryLog : public Log
45 boost::mutex::scoped_lock (_mutex);
50 void do_log (string m)
58 static shared_ptr<MemoryLog> memory_log (new MemoryLog);
60 class StatusDialog : public wxDialog
64 : wxDialog (0, wxID_ANY, _("DCP-o-matic encode server"), wxDefaultPosition, wxSize (600, 80), wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER)
65 , _timer (this, ID_timer)
67 _sizer = new wxFlexGridSizer (1, 6, 6);
68 _sizer->AddGrowableCol (0, 1);
70 _text = new wxTextCtrl (this, wxID_ANY, _(""), wxDefaultPosition, wxDefaultSize, wxTE_READONLY);
71 _sizer->Add (_text, 1, wxEXPAND);
76 Connect (ID_timer, wxEVT_TIMER, wxTimerEventHandler (StatusDialog::update));
81 void update (wxTimerEvent &)
83 _text->ChangeValue (std_to_wx (memory_log->get ()));
87 wxFlexGridSizer* _sizer;
92 class TaskBarIcon : public wxTaskBarIcon
98 wxIcon icon (std_to_wx ("taskbar_icon"));
101 wxInitAllImageHandlers();
102 wxBitmap bitmap (wxString::Format (wxT ("%s/taskbar_icon.png"), POSIX_ICON_PREFIX), wxBITMAP_TYPE_PNG);
104 icon.CopyFromBitmap (bitmap);
107 /* XXX: fix this for OS X */
108 SetIcon (icon, std_to_wx ("DCP-o-matic encode server"));
111 Connect (ID_status, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler (TaskBarIcon::status));
112 Connect (ID_quit, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler (TaskBarIcon::quit));
115 wxMenu* CreatePopupMenu ()
117 wxMenu* menu = new wxMenu;
118 menu->Append (ID_status, std_to_wx ("Status..."));
119 menu->Append (ID_quit, std_to_wx ("Quit"));
124 void status (wxCommandEvent &)
126 StatusDialog* d = new StatusDialog;
130 void quit (wxCommandEvent &)
132 wxTheApp->ExitMainLoop ();
136 class App : public wxApp
149 if (!wxApp::OnInit ()) {
155 _icon = new TaskBarIcon;
156 _thread = new thread (bind (&App::main_thread, this));
164 return wxApp::OnExit ();
169 Server server (memory_log);
170 server.run (Config::instance()->num_local_encoding_threads ());
173 boost::thread* _thread;