preferences.cpp

00001 
00004 /*
00005                 vdr_remote - A Graphic Remote Control Utility for Klaus Schidinger's vdr (www.cadsoft.de/vdr)
00006 
00007                 Copyright (C)2006 Peter Marquardt p_marquardt@users.sourceforge.net
00008  */
00009 /*
00010                 This program is free software; you can redistribute it and/or modify
00011                 it under the terms of the GNU General Public License as published by
00012                 the Free Software Foundation; either version 2 of the License, or
00013                 (at your option) any later version.
00014 
00015                 This program is distributed in the hope that it will be useful,
00016                 but WITHOUT ANY WARRANTY; without even the implied warranty of
00017                 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00018                 GNU General Public License for more details.
00019 
00020                 You should have received a copy of the GNU General Public License
00021                 along with this program; if not, write to the Free Software
00022                 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00023 */
00024                 
00025                 
00026 
00027 #include "vdr_remote.h"
00028 
00029 
00030                 extern wxConfig *my_prefs;
00031                 extern bool show_socket_viewer;
00032                 extern bool show_player_buttons;
00033                 extern bool show_user_buttons;
00034                 extern wxString vdr_host;
00035                 extern long vdr_port;
00036 //              extern wxArrayString my_user_button_titles;
00037                 
00038 void vdr_remoteFrame::LoadPreferences() {
00039         if (!my_prefs->Read(wxT("vdr_host"), &vdr_host)) 
00040         {
00041                 vdr_host = wxT("192.168.100.100");
00042                 my_prefs->Write(wxT("vdr_host"), vdr_host);
00043                 my_prefs->Flush();
00044         }
00045         if (!my_prefs->Read(wxT("vdr_port"),&vdr_port))
00046         {
00047                 vdr_port = 2001;
00048                 my_prefs->Write(wxT("vdr_port"), vdr_port);
00049                 my_prefs->Flush();
00050         }
00051         if (!my_prefs->Read(wxT("show_socket_viewer"), &show_socket_viewer))
00052         {
00053                 show_socket_viewer = false;
00054                 my_prefs->Write(wxT("show_socket_viewer"), show_socket_viewer);
00055                 my_prefs->Flush();
00056         }
00057         if (!my_prefs->Read(wxT("show_player_buttons"), &show_player_buttons))
00058         {
00059                 show_player_buttons = true;
00060                 my_prefs->Write(wxT("show_player_buttons"), show_player_buttons);
00061                 my_prefs->Flush();
00062         }
00063         if (!my_prefs->Read(wxT("show_user_buttons"), &show_user_buttons))
00064         {
00065                 show_user_buttons = true;
00066                 my_prefs->Write(wxT("show_user_buttons"), show_user_buttons);
00067                 my_prefs->Flush();
00068         }
00069         my_user_button_titles.Insert(wxT(""),0);
00070         for (int i = 1; i <= NUM_USER_BUTTONS; i++)
00071         {
00072                 wxString prefsString =wxT("User Command "), prefsFileString  = wxT("title_user_button_");
00073                 prefsString << i;
00074                 prefsFileString << i;
00075                 my_user_button_titles.Insert(prefsString,i);
00076                 if (!my_prefs->Read(prefsFileString, &my_user_button_titles[i]))
00077                 {
00078                 
00079                         my_prefs->Write(prefsFileString, my_user_button_titles[i]);
00080                         my_prefs->Flush();
00081                 }       
00082         }
00083         if (!my_prefs->Read(wxT("disk_status_timeout"), &disk_status_timeout))
00084         {
00085                 disk_status_timeout = 750;
00086                 my_prefs->Write(wxT("disk_status_timeout"), disk_status_timeout);
00087                 my_prefs->Flush();
00088         }
00089 }
00090 
00091 void vdr_remoteFrame::OnBtnPrefs( wxCommandEvent& event)
00092 {
00093         wxDialog * prefs_dlog = new wxDialog (this, -1, wxT("Preferences"),wxPoint(50,50),wxSize(270,300));
00094         wxBoxSizer *prefs_sizer = new wxBoxSizer(wxVERTICAL);
00095         wxString temp_host(vdr_host),temp_port;
00096         bool prefs_show_socket_viewer = show_socket_viewer;
00097         bool prefs_show_player_buttons = show_player_buttons;
00098         bool prefs_show_user_buttons = show_user_buttons;
00099         wxArrayString temp_userbuttons = my_user_button_titles;
00100         temp_port << vdr_port;
00101         wxFlexGridSizer *prefs_box = new wxFlexGridSizer(5,2,4,4);
00102         wxBoxSizer * button_box = new wxBoxSizer(wxHORIZONTAL);
00103         wxTextCtrl *prefs_adress = new wxTextCtrl (prefs_dlog,-1,temp_host,wxPoint(-1,-1),wxSize(TXTCTRL_WIDTH,20),0,wxTextValidator(wxFILTER_ASCII, &temp_host));
00104         wxTextCtrl *prefs_port = new wxTextCtrl (prefs_dlog,-1,temp_port,wxPoint(-1,-1),wxSize(TXTCTRL_WIDTH,20),0,wxTextValidator(wxFILTER_NUMERIC,&temp_port));
00105         wxCheckBox *prefs_show_viewer = new wxCheckBox(prefs_dlog, -1, wxT("Show Vdr's responses"),  wxPoint(-1,-1),wxSize(-1,-1),0,wxGenericValidator(&prefs_show_socket_viewer));
00106         wxCheckBox *prefs_show_plbtn = new wxCheckBox(prefs_dlog, -1, wxT("Show Player buttons"),  wxPoint(-1,-1),wxSize(-1,-1),0,wxGenericValidator(&prefs_show_player_buttons));
00107         wxCheckBox *prefs_show_ubtn = new wxCheckBox(prefs_dlog, -1, wxT("Show User buttons"),  wxPoint(-1,-1),wxSize(-1,-1),0,wxGenericValidator(&prefs_show_user_buttons));
00108         
00109         wxStaticText * txt_adr = new wxStaticText(prefs_dlog,-1,wxT("vdr Hostname or IP Adress"));
00110         wxStaticText * txt_port = new wxStaticText(prefs_dlog,-1,wxT("vdr SVDRP Port\ndefault: 2001"));
00111         wxStaticText * txt_user1 = new wxStaticText(prefs_dlog,-1,wxT("User Button 1 Tooltip"));
00112         wxTextCtrl * prefs_user1 = new wxTextCtrl(prefs_dlog, -1, my_user_button_titles[1], wxDefaultPosition,wxSize(TXTCTRL_WIDTH,20), 0, wxTextValidator(wxFILTER_ASCII,&my_user_button_titles[1]));
00113         wxStaticText * txt_user2 = new wxStaticText(prefs_dlog,-1,wxT("User Button 2 Tooltip"));
00114         wxTextCtrl * prefs_user2 = new wxTextCtrl(prefs_dlog, -1, my_user_button_titles[2], wxDefaultPosition,wxSize(TXTCTRL_WIDTH,20), 0, wxTextValidator(wxFILTER_ASCII,&my_user_button_titles[2]));
00115         wxStaticText * txt_user3 = new wxStaticText(prefs_dlog,-1,wxT("User Button 3 Tooltip"));
00116         wxTextCtrl * prefs_user3 = new wxTextCtrl(prefs_dlog, -1, my_user_button_titles[3], wxDefaultPosition,wxSize(TXTCTRL_WIDTH,20), 0, wxTextValidator(wxFILTER_ASCII,&my_user_button_titles[3]));
00117         wxStaticText * txt_user4 = new wxStaticText(prefs_dlog,-1,wxT("User Button 4 Tooltip"));
00118         wxTextCtrl * prefs_user4 = new wxTextCtrl(prefs_dlog, -1, my_user_button_titles[4], wxDefaultPosition,wxSize(TXTCTRL_WIDTH,20), 0, wxTextValidator(wxFILTER_ASCII,&my_user_button_titles[4]));
00119         wxStaticText * txt_user5 = new wxStaticText(prefs_dlog,-1,wxT("User Button 5 Tooltip"));
00120         wxTextCtrl * prefs_user5 = new wxTextCtrl(prefs_dlog, -1, my_user_button_titles[5], wxDefaultPosition,wxSize(TXTCTRL_WIDTH,20), 0, wxTextValidator(wxFILTER_ASCII,&my_user_button_titles[5]));
00121         wxStaticText * txt_user6 = new wxStaticText(prefs_dlog,-1,wxT("User Button 6 Tooltip"));
00122         wxTextCtrl * prefs_user6 = new wxTextCtrl(prefs_dlog, -1, my_user_button_titles[6], wxDefaultPosition,wxSize(TXTCTRL_WIDTH,20), 0, wxTextValidator(wxFILTER_ASCII,&my_user_button_titles[6]));
00123         wxStaticText * txt_user7 = new wxStaticText(prefs_dlog,-1,wxT("User Button 7 Tooltip"));
00124         wxTextCtrl * prefs_user7 = new wxTextCtrl(prefs_dlog, -1, my_user_button_titles[7], wxDefaultPosition,wxSize(TXTCTRL_WIDTH,20), 0, wxTextValidator(wxFILTER_ASCII,&my_user_button_titles[7]));
00125         wxStaticText * txt_user8 = new wxStaticText(prefs_dlog,-1,wxT("User Button 8 Tooltip"));
00126         wxTextCtrl * prefs_user8 = new wxTextCtrl(prefs_dlog, -1, my_user_button_titles[8], wxDefaultPosition,wxSize(TXTCTRL_WIDTH,20), 0, wxTextValidator(wxFILTER_ASCII,&my_user_button_titles[8]));
00127         wxStaticText * txt_user9 = new wxStaticText(prefs_dlog,-1,wxT("User Button 9 Tooltip"));
00128         wxTextCtrl * prefs_user9 = new wxTextCtrl(prefs_dlog, -1, my_user_button_titles[9], wxDefaultPosition,wxSize(TXTCTRL_WIDTH,20), 0, wxTextValidator(wxFILTER_ASCII,&my_user_button_titles[9]));
00129         wxStaticText * txt_disk_timeout = new wxStaticText(prefs_dlog,-1,wxT("Timeout for disk status (ms)\ndefault: 750"));
00130         wxSpinCtrl * prefs_ds_timeout = new wxSpinCtrl( prefs_dlog, Spin_Disk_Stat_Timeout, wxT(""), wxDefaultPosition, wxDefaultSize, wxSP_ARROW_KEYS, 25,1500, disk_status_timeout);
00131         prefs_ds_timeout->Connect(Spin_Disk_Stat_Timeout,wxEVT_COMMAND_SPINCTRL_UPDATED,wxSpinEventHandler(vdr_remoteFrame::OnSpinEvent),NULL,this);
00132         wxButton * prefButton_Ok = new wxButton(prefs_dlog,wxID_OK);
00133         wxButton * prefButton_Cancel = new wxButton(prefs_dlog, wxID_CANCEL);
00134         button_box->AddSpacer(100);
00135         button_box->Add(prefButton_Cancel);
00136         button_box->AddSpacer(6);
00137         button_box->Add(prefButton_Ok);
00138         prefs_box->Add(txt_adr);
00139         prefs_box->Add(prefs_adress);
00140         prefs_box->Add(txt_port);
00141         prefs_box->Add(prefs_port);
00142         prefs_box->AddStretchSpacer();
00143         prefs_box->Add(prefs_show_plbtn);
00144         prefs_box->AddStretchSpacer();
00145         prefs_box->Add(prefs_show_ubtn);
00146         prefs_box->AddStretchSpacer();
00147         prefs_box->Add(prefs_show_viewer);
00148         prefs_box->Add(txt_disk_timeout);
00149         prefs_box->Add(prefs_ds_timeout);
00150         prefs_box->Add(txt_user1);
00151         prefs_box->Add(prefs_user1);
00152         prefs_box->Add(txt_user2);
00153         prefs_box->Add(prefs_user2);
00154         prefs_box->Add(txt_user3);
00155         prefs_box->Add(prefs_user3);
00156         prefs_box->Add(txt_user4);
00157         prefs_box->Add(prefs_user4);
00158         prefs_box->Add(txt_user5);
00159         prefs_box->Add(prefs_user5);
00160         prefs_box->Add(txt_user6);
00161         prefs_box->Add(prefs_user6);
00162         prefs_box->Add(txt_user7);
00163         prefs_box->Add(prefs_user7);
00164         prefs_box->Add(txt_user8);
00165         prefs_box->Add(prefs_user8);
00166         prefs_box->Add(txt_user9);
00167         prefs_box->Add(prefs_user9);
00168         prefs_sizer->AddSpacer(8);
00169         prefs_sizer->Add(prefs_box);
00170         prefs_sizer->AddSpacer(8);
00171         prefs_sizer->Add(button_box);
00172         prefs_dlog->SetSizerAndFit(prefs_sizer);
00173 
00174         prefs_dlog->Layout();
00175         
00176         if (prefs_dlog->ShowModal() == wxID_OK) 
00177         {
00178                 vdr_host =temp_host;
00179                 my_prefs->Write(wxT("vdr_host"), vdr_host);
00180                 temp_port.ToLong(&vdr_port);
00181                 my_prefs->Write(wxT("vdr_port"), vdr_port);
00182                 show_socket_viewer = prefs_show_socket_viewer;
00183                 my_prefs->Write(wxT("show_socket_viewer"), show_socket_viewer);
00184                 show_player_buttons = prefs_show_player_buttons;
00185                 my_prefs->Write(wxT("show_player_buttons"), show_player_buttons);
00186                 show_user_buttons = prefs_show_user_buttons;
00187                 my_prefs->Write(wxT("show_user_buttons"), show_user_buttons);
00188                 my_prefs->Flush();
00189 
00190                 for (int i = 1; i <= NUM_USER_BUTTONS; i++)
00191                 {
00192                         wxString prefsFileString  = wxT("title_user_button_");
00193                         prefsFileString << i;
00194                         my_prefs->Write(prefsFileString, my_user_button_titles[i]);
00195                 }
00196                 my_prefs->Write(wxT("disk_status_timeout"), disk_status_timeout); //We don't need a validator here, disk_status_timeout will be set in SpinCtrlEvent Handler OnSpinEvent()
00197                 my_prefs->Flush();
00198         }
00199         key_ok->SetFocus(); //automatically set focus back to ok button so Return works as expected on windows
00200 
00201 }

Generated on Sun Nov 5 22:39:02 2006 for vdr_remote by  doxygen 1.4.6