2 Copyright (C) 2012-2015 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 "wx/wx_util.h"
22 #include "lib/server.h"
23 #include "lib/config.h"
25 #include <wx/taskbar.h>
27 #include <boost/thread.hpp>
33 using boost::shared_ptr;
43 class MemoryLog : public Log
48 boost::mutex::scoped_lock (_mutex);
52 string head_and_tail (int amount = 1024) const {
53 if (int (_log.size ()) < (2 * amount)) {
57 return _log.substr (0, amount) + _log.substr (_log.size() - amount - 1, amount);
61 void do_log (string m)
69 static shared_ptr<MemoryLog> memory_log (new MemoryLog);
72 class StatusDialog : public wxFrame
74 class StatusDialog : public wxDialog
80 : wxFrame (0, wxID_ANY, _("DCP-o-matic encode server"), wxDefaultPosition, wxSize (600, 80), wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER)
82 : wxDialog (0, wxID_ANY, _("DCP-o-matic encode server"), wxDefaultPosition, wxSize (600, 80), wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER)
84 , _timer (this, ID_timer)
86 _sizer = new wxFlexGridSizer (1, 6, 6);
87 _sizer->AddGrowableCol (0, 1);
89 _text = new wxTextCtrl (this, wxID_ANY, _(""), wxDefaultPosition, wxDefaultSize, wxTE_READONLY);
90 _sizer->Add (_text, 1, wxEXPAND);
95 Bind (wxEVT_TIMER, boost::bind (&StatusDialog::update, this), ID_timer);
102 _text->ChangeValue (std_to_wx (memory_log->get ()));
106 wxFlexGridSizer* _sizer;
111 class TaskBarIcon : public wxTaskBarIcon
116 #ifdef DCPOMATIC_WINDOWS
117 wxIcon icon (std_to_wx ("taskbar_icon"));
120 #ifdef DCPOMATIC_LINUX
121 wxInitAllImageHandlers();
122 wxBitmap bitmap (wxString::Format (wxT ("%s/dcpomatic2_server_small.png"), LINUX_SHARE_PREFIX), wxBITMAP_TYPE_PNG);
124 icon.CopyFromBitmap (bitmap);
127 #ifndef DCPOMATIC_OSX
128 SetIcon (icon, std_to_wx ("DCP-o-matic encode server"));
133 Bind (wxEVT_COMMAND_MENU_SELECTED, boost::bind (&TaskBarIcon::status, this), ID_status);
134 Bind (wxEVT_COMMAND_MENU_SELECTED, boost::bind (&TaskBarIcon::quit, this), ID_quit);
137 wxMenu* CreatePopupMenu ()
139 wxMenu* menu = new wxMenu;
140 menu->Append (ID_status, std_to_wx ("Status..."));
141 menu->Append (ID_quit, std_to_wx ("Quit"));
148 StatusDialog* d = new StatusDialog;
154 wxTheApp->ExitMainLoop ();
158 class App : public wxApp, public ExceptionStore
171 if (!wxApp::OnInit ()) {
175 dcpomatic_setup_path_encoding ();
176 dcpomatic_setup_i18n ();
180 _icon = new TaskBarIcon;
181 _thread = new thread (bind (&App::main_thread, this));
183 Bind (wxEVT_TIMER, boost::bind (&App::check, this));
184 _timer.reset (new wxTimer (this));
185 _timer->Start (1000);
188 wxMenu* file = new wxMenu;
189 file->Append (wxID_EXIT, _("&Exit"));
190 wxMenuBar* bar = new wxMenuBar;
191 bar->Append (file, _("&File"));
201 return wxApp::OnExit ();
206 Server server (memory_log, false);
207 server.run (Config::instance()->num_local_encoding_threads ());
216 } catch (exception& e) {
217 error_dialog (0, std_to_wx (e.what ()));
218 wxTheApp->ExitMainLoop ();
220 error_dialog (0, _("An unknown error has occurred with the DCP-o-matic server."));
221 wxTheApp->ExitMainLoop ();
225 boost::thread* _thread;
227 shared_ptr<wxTimer> _timer;