2024.8.23
Loading...
Searching...
No Matches
class.action.changeBrowser.php
Go to the documentation of this file.
1<?php
2/*
3 * Copyright (c) 2021-2024 Bearsampp
4 * License: GNU General Public License version 3 or later; see LICENSE.txt
5 * Author: Bear
6 * Website: https://bearsampp.com
7 * Github: https://github.com/Bearsampp
8 */
9
10/**
11 * Class ActionChangeBrowser
12 *
13 * This class handles the action of changing the default browser in the Bearsampp application.
14 * It creates a window with options to select from installed browsers or browse for a different browser executable.
15 * The selected browser is then saved in the configuration.
16 */
18{
19 private $wbWindow;
20 private $wbLabelExp;
24 private $wbBtnBrowse;
26 private $wbBtnSave;
27 private $wbBtnCancel;
28
29 const GAUGE_SAVE = 2;
30
31 /**
32 * Constructor for ActionChangeBrowser.
33 *
34 * Initializes the window and its components, sets up event handlers, and starts the main loop.
35 *
36 * @param array $args Arguments passed to the constructor.
37 */
38 public function __construct($args)
39 {
40 global $bearsamppConfig, $bearsamppLang, $bearsamppWinbinder;
41
42 $bearsamppWinbinder->reset();
43 $this->wbWindow = $bearsamppWinbinder->createAppWindow($bearsamppLang->getValue(Lang::CHANGE_BROWSER_TITLE), 490, 350, WBC_NOTIFY, WBC_KEYDOWN | WBC_KEYUP);
44
45 $this->wbLabelExp = $bearsamppWinbinder->createLabel($this->wbWindow, $bearsamppLang->getValue(Lang::CHANGE_BROWSER_EXP_LABEL), 15, 15, 470, 50);
46
47 $currentBrowser = $bearsamppConfig->getBrowser();
48 $this->wbRadioButton[] = $bearsamppWinbinder->createRadioButton($this->wbWindow, $currentBrowser, true, 15, 40, 470, 20, true);
49
50 $yPos = 70;
51 $installedBrowsers = Vbs::getInstalledBrowsers();
52 foreach ($installedBrowsers as $installedBrowser) {
53 if ($installedBrowser != $currentBrowser) {
54 $this->wbRadioButton[] = $bearsamppWinbinder->createRadioButton($this->wbWindow, $installedBrowser, false, 15, $yPos, 470, 20);
55 $yPos += 30;
56 }
57 }
58
59 $this->wbRadioButtonOther = $bearsamppWinbinder->createRadioButton($this->wbWindow, $bearsamppLang->getValue(Lang::CHANGE_BROWSER_OTHER_LABEL), false, 15, $yPos, 470, 15);
60
61 $this->wbInputBrowse = $bearsamppWinbinder->createInputText($this->wbWindow, null, 30, $yPos + 30, 190, null, 20, WBC_READONLY);
62 $this->wbBtnBrowse = $bearsamppWinbinder->createButton($this->wbWindow, $bearsamppLang->getValue(Lang::BUTTON_BROWSE), 225, $yPos + 25, 110);
63 $bearsamppWinbinder->setEnabled($this->wbBtnBrowse[WinBinder::CTRL_OBJ], false);
64
65 $this->wbProgressBar = $bearsamppWinbinder->createProgressBar($this->wbWindow, self::GAUGE_SAVE, 15, 287, 275);
66 $this->wbBtnSave = $bearsamppWinbinder->createButton($this->wbWindow, $bearsamppLang->getValue(Lang::BUTTON_SAVE), 300, 282);
67 $this->wbBtnCancel = $bearsamppWinbinder->createButton($this->wbWindow, $bearsamppLang->getValue(Lang::BUTTON_CANCEL), 387, 282);
68 $bearsamppWinbinder->setEnabled($this->wbBtnSave[WinBinder::CTRL_OBJ], empty($currentBrowser) ? false : true);
69
70 $bearsamppWinbinder->setHandler($this->wbWindow, $this, 'processWindow');
71 $bearsamppWinbinder->mainLoop();
72 $bearsamppWinbinder->reset();
73 }
74
75 /**
76 * Processes window events.
77 *
78 * Handles the logic for various controls in the window, such as enabling/disabling buttons,
79 * opening file dialogs, and saving the selected browser.
80 *
81 * @param resource $window The window resource.
82 * @param int $id The ID of the control that triggered the event.
83 * @param resource $ctrl The control resource.
84 * @param mixed $param1 Additional parameter 1.
85 * @param mixed $param2 Additional parameter 2.
86 */
87 public function processWindow($window, $id, $ctrl, $param1, $param2)
88 {
89 global $bearsamppConfig, $bearsamppLang, $bearsamppWinbinder;
90
91 // Get other value
92 $browserPath = $bearsamppWinbinder->getText($this->wbInputBrowse[WinBinder::CTRL_OBJ]);
93
94 // Get value
95 $selected = null;
96 if ($bearsamppWinbinder->getValue($this->wbRadioButtonOther[WinBinder::CTRL_OBJ]) == 1) {
97 $bearsamppWinbinder->setEnabled($this->wbBtnBrowse[WinBinder::CTRL_OBJ], true);
98 $selected = $bearsamppWinbinder->getText($this->wbInputBrowse[WinBinder::CTRL_OBJ]);
99 } else {
100 $bearsamppWinbinder->setEnabled($this->wbBtnBrowse[WinBinder::CTRL_OBJ], false);
101 }
102 foreach ($this->wbRadioButton as $radioButton) {
103 if ($bearsamppWinbinder->getValue($radioButton[WinBinder::CTRL_OBJ]) == 1) {
104 $selected = $bearsamppWinbinder->getText($radioButton[WinBinder::CTRL_OBJ]);
105 break;
106 }
107 }
108
109 // Enable/disable save button
110 $bearsamppWinbinder->setEnabled($this->wbBtnSave[WinBinder::CTRL_OBJ], empty($selected) ? false : true);
111
112 switch ($id) {
113 case $this->wbBtnBrowse[WinBinder::CTRL_ID]:
114 $browserPath = trim($bearsamppWinbinder->sysDlgOpen(
115 $window,
117 array(array($bearsamppLang->getValue(Lang::EXECUTABLE), '*.exe')),
118 $browserPath
119 ));
120 if ($browserPath && is_file($browserPath)) {
121 $bearsamppWinbinder->setText($this->wbInputBrowse[WinBinder::CTRL_OBJ], $browserPath);
122 }
123 break;
124 case $this->wbBtnSave[WinBinder::CTRL_ID]:
125 $bearsamppWinbinder->incrProgressBar($this->wbProgressBar);
126
127 $bearsamppWinbinder->incrProgressBar($this->wbProgressBar);
128 $bearsamppConfig->replace(Config::CFG_BROWSER, $selected);
129
130 $bearsamppWinbinder->messageBoxInfo(
131 sprintf($bearsamppLang->getValue(Lang::CHANGE_BROWSER_OK), $selected),
133 );
134 $bearsamppWinbinder->destroyWindow($window);
135
136 break;
137 case IDCLOSE:
138 case $this->wbBtnCancel[WinBinder::CTRL_ID]:
139 $bearsamppWinbinder->destroyWindow($window);
140 break;
141 }
142 }
143}
global $bearsamppLang
processWindow($window, $id, $ctrl, $param1, $param2)
const CFG_BROWSER
const ALIAS_DEST_PATH
const CHANGE_BROWSER_OK
const CHANGE_BROWSER_TITLE
const BUTTON_CANCEL
const BUTTON_SAVE
const CHANGE_BROWSER_EXP_LABEL
const EXECUTABLE
const BUTTON_BROWSE
const CHANGE_BROWSER_OTHER_LABEL
static getInstalledBrowsers()
global $bearsamppConfig
Definition homepage.php:26