replaced cec-config-gui by libCEC tray
[deb_libcec.git] / src / LibCecTray / controller / applications / ConfigureApplication.cs
CommitLineData
f017f3c4
LOK
1/*
2 * This file is part of the libCEC(R) library.
3 *
4 * libCEC(R) is Copyright (C) 2011-2012 Pulse-Eight Limited. All rights reserved.
5 * libCEC(R) is an original work, containing original code.
6 *
7 * libCEC(R) is a trademark of Pulse-Eight Limited.
8 *
9 * This program is dual-licensed; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22 *
23 *
24 * Alternatively, you can license this library under a commercial license,
25 * please contact Pulse-Eight Licensing for more information.
26 *
27 * For more information contact:
28 * Pulse-Eight Licensing <license@pulse-eight.com>
29 * http://www.pulse-eight.com/
30 * http://www.pulse-eight.net/
31 */
32
33using System;
34using System.ComponentModel;
35using System.Diagnostics;
36using System.Drawing;
37using System.IO;
38using System.Windows.Forms;
39using LibCECTray.Properties;
40using LibCECTray.settings;
41using LibCECTray.ui;
42
43namespace LibCECTray.controller.applications
44{
45 partial class ConfigureApplication : Form
46 {
47 public ConfigureApplication(ApplicationController controller) :
48 this(null, null)
49 {
50 _controller = controller;
51 tbFilename.Text = controller.ApplicationFilename;
52 tbWorkingDir.Text = controller.ApplicationWorkingDirectory;
53 tbUiName.Text = controller.UiName;
54 tbProcessName.Text = controller.ProcessName;
55
56 Text = string.Format(Resources.configure_application, controller.UiName);
57
58 if (!_controller.CanConfigureProcess)
59 {
60 tbFilename.Enabled = false;
61 tbWorkingDir.Enabled = false;
62 tbUiName.Enabled = false;
63 tbProcessName.Enabled = false;
64 bFindFile.Enabled = false;
65 }
66 }
67
68 public override sealed string Text
69 {
70 get { return base.Text; }
71 set { base.Text = value; }
72 }
73
74 public ConfigureApplication(CECSettings settings, CECController controller)
75 {
76 _cecController = controller;
77 _settings = settings;
78 InitializeComponent();
79
80 // take the icon of the main window
81 ComponentResourceManager resources = new ComponentResourceManager(typeof(CECTray));
82 Icon = resources.GetObject("$this.Icon") as Icon;
83
84 Text = Resources.add_new_application;
85 }
86
87 private void BFindFileClick(object sender, EventArgs e)
88 {
89 OpenFileDialog dialog = new OpenFileDialog
90 {
91 Title = Resources.select_exe_file,
92 InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments),
93 Filter = Resources.exe_file_filter,
94 FilterIndex = 1
95 };
96
97 if (dialog.ShowDialog() != DialogResult.OK) return;
98
99 var fileName = dialog.SafeFileName;
100 if (fileName != null && File.Exists(dialog.FileName))
101 {
102 var versionInfo = FileVersionInfo.GetVersionInfo(dialog.FileName);
103 var path = dialog.FileName.Substring(0, dialog.FileName.Length - fileName.Length);
104 if (path.EndsWith("\\"))
105 path = path.Substring(0, path.Length - 1);
106
107 tbFilename.Text = fileName;
108 tbWorkingDir.Text = path;
109 tbUiName.Text = versionInfo.FileDescription;
110 tbProcessName.Text = fileName;
111 Text = string.Format(Resources.configure_application, versionInfo.FileDescription);
112 }
113 else
114 {
115 tbFilename.Text = string.Empty;
116 tbWorkingDir.Text = string.Empty;
117 tbUiName.Text = string.Empty;
118 tbProcessName.Text = string.Empty;
119 Text = Resources.add_new_application;
120 }
121 }
122
123 private void BOkClick(object sender, EventArgs e)
124 {
125 if (_controller != null)
126 {
127 _controller.ApplicationFilename = tbFilename.Text;
128 _controller.ApplicationWorkingDirectory = tbWorkingDir.Text;
129 _controller.UiName = tbUiName.Text;
130 _controller.ProcessName = tbProcessName.Text;
131 _controller.Settings.Persist();
132 }
133 else if (_cecController != null)
134 {
135 ApplicationController newController = new ApplicationController(_settings, tbUiName.Text, tbProcessName.Text, tbFilename.Text, tbWorkingDir.Text);
136 if (_cecController.RegisterApplication(newController))
137 newController.Settings.Persist();
138 }
139 Dispose();
140 }
141
142 private void BCancelClick(object sender, EventArgs e)
143 {
144 //TODO
145 Dispose();
146 }
147
148 private ApplicationController _controller;
149 private CECController _cecController;
150 private CECSettings _settings;
151 }
152}