atraczyk | 61b2842 | 2016-08-24 09:25:59 -0400 | [diff] [blame] | 1 | /**************************************************************************
|
| 2 | * Copyright (C) 2016 by Savoir-faire Linux *
|
| 3 | * Author: Jäger Nicolas <nicolas.jager@savoirfairelinux.com> *
|
| 4 | * *
|
| 5 | * This program is free software; you can redistribute it and/or modify *
|
| 6 | * it under the terms of the GNU General Public License as published by *
|
| 7 | * the Free Software Foundation; either version 3 of the License, or *
|
| 8 | * (at your option) any later version. *
|
| 9 | * *
|
| 10 | * This program is distributed in the hope that it will be useful, *
|
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
| 13 | * GNU General Public License for more details. *
|
| 14 | * *
|
| 15 | * You should have received a copy of the GNU General Public License *
|
| 16 | * along with this program. If not, see <http://www.gnu.org/licenses/>. *
|
| 17 | **************************************************************************/
|
| 18 | #include "pch.h"
|
| 19 |
|
| 20 | #include "RingConsolePanel.xaml.h"
|
| 21 |
|
| 22 | using namespace RingClientUWP;
|
| 23 | using namespace RingClientUWP::Views;
|
Nicolas Jager | 4569bf5 | 2016-11-03 11:13:47 -0400 | [diff] [blame] | 24 | using namespace RingClientUWP::ViewModel;
|
atraczyk | 61b2842 | 2016-08-24 09:25:59 -0400 | [diff] [blame] | 25 | using namespace Windows::ApplicationModel::Core;
|
| 26 | using namespace Windows::UI::Core;
|
| 27 | using namespace Windows::UI::Xaml::Documents;
|
| 28 |
|
| 29 | RingConsolePanel::RingConsolePanel()
|
| 30 | {
|
| 31 | InitializeComponent();
|
| 32 |
|
| 33 | RingDebug::instance->messageToScreen += ref new debugMessageToScreen([this](Platform::String^ message) {
|
atraczyk | 746f376 | 2017-02-28 14:12:51 -0500 | [diff] [blame^] | 34 | CoreApplication::MainView->CoreWindow->Dispatcher->RunAsync(CoreDispatcherPriority::High,
|
| 35 | ref new DispatchedHandler([=]()
|
| 36 | {
|
| 37 | output(message);
|
| 38 | }));
|
atraczyk | 61b2842 | 2016-08-24 09:25:59 -0400 | [diff] [blame] | 39 | });
|
| 40 | }
|
| 41 |
|
| 42 | void
|
| 43 | RingConsolePanel::output(Platform::String^ message)
|
| 44 | {
|
| 45 | try {
|
| 46 | Run^ inlineText = ref new Run();
|
| 47 | inlineText->Text = message;
|
| 48 | Paragraph^ paragraph = ref new Paragraph();
|
| 49 | paragraph->Inlines->Append(inlineText);
|
| 50 | _debugWindowOutput_->Blocks->Append(paragraph);
|
| 51 | _scrollView_->UpdateLayout();
|
| 52 | _scrollView_->ScrollToVerticalOffset(_scrollView_->ScrollableHeight);
|
| 53 | }
|
| 54 | catch (Platform::Exception^ e) {
|
| 55 | return;
|
| 56 | }
|
| 57 | }
|
| 58 |
|
| 59 | void RingConsolePanel::_btnSendDbgCmd__Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e)
|
| 60 | {
|
| 61 | sendCommand();
|
| 62 | }
|
| 63 |
|
| 64 |
|
| 65 | void RingConsolePanel::_sendDbgCmd__KeyDown(Platform::Object^ sender, Windows::UI::Xaml::Input::KeyRoutedEventArgs^ e)
|
| 66 | {
|
| 67 | if (e->Key == Windows::System::VirtualKey::Enter && _tBoxDbg_->Text != "") {
|
| 68 | sendCommand();
|
| 69 | }
|
| 70 | else if (e->Key == Windows::System::VirtualKey::PageUp) {
|
| 71 |
|
| 72 | if (historyLevel < 1)
|
| 73 | return;
|
| 74 | if (historyLevel == historyCmds.Size)
|
| 75 | currentCmd = _tBoxDbg_->Text;
|
| 76 | historyLevel--;
|
| 77 | _tBoxDbg_->Text = historyCmds.GetAt(historyLevel);
|
| 78 |
|
| 79 | }
|
| 80 | else if (e->Key == Windows::System::VirtualKey::PageDown) {
|
| 81 | if (historyLevel < historyCmds.Size) {
|
| 82 | _tBoxDbg_->Text = historyCmds.GetAt(historyLevel);
|
| 83 | historyLevel++;
|
| 84 |
|
| 85 | }
|
| 86 | else {
|
| 87 | _tBoxDbg_->Text = currentCmd;
|
| 88 | }
|
| 89 | return;
|
| 90 | }
|
| 91 | }
|
| 92 |
|
| 93 | /*\ ADD EACH NEW COMMAND TO THE HELP LIST \*/
|
| 94 | void RingConsolePanel::sendCommand()
|
| 95 | {
|
Nicolas Jager | 4569bf5 | 2016-11-03 11:13:47 -0400 | [diff] [blame] | 96 | auto inputConst_str = Utils::toString(_tBoxDbg_->Text);
|
| 97 | if (inputConst_str.empty())
|
| 98 | return;
|
| 99 |
|
| 100 | auto inputConst_cstr = inputConst_str.c_str();
|
| 101 | char* input_cstr = _strdup(inputConst_cstr); // full string
|
| 102 | char* input_cstr_nextToken; // tokenized string
|
| 103 | char* cmd_cstr = strtok_s(input_cstr, " ", &input_cstr_nextToken);
|
| 104 | char* parameter1_cstr = strtok_s(input_cstr_nextToken, " ", &input_cstr_nextToken);
|
| 105 | // parameter2...
|
| 106 |
|
| 107 | if (!cmd_cstr)
|
| 108 | return;
|
| 109 |
|
| 110 | std::string input(cmd_cstr);
|
| 111 | std::string parameter1;
|
| 112 |
|
| 113 | if (parameter1_cstr)
|
| 114 | parameter1 = parameter1_cstr;
|
| 115 |
|
| 116 | free(input_cstr);
|
| 117 | free(input_cstr_nextToken);
|
| 118 | //free((char*)inputConst_cstr);
|
| 119 |
|
atraczyk | 61b2842 | 2016-08-24 09:25:59 -0400 | [diff] [blame] | 120 | addCommandToHistory();
|
| 121 | historyLevel++;
|
| 122 | _tBoxDbg_->Text = "";
|
| 123 | currentCmd = "";
|
| 124 | historyLevel = historyCmds.Size;
|
| 125 |
|
Nicolas Jager | 4569bf5 | 2016-11-03 11:13:47 -0400 | [diff] [blame] | 126 | if (input == "help") {
|
atraczyk | 61b2842 | 2016-08-24 09:25:59 -0400 | [diff] [blame] | 127 | MSG_(">> Help :");
|
| 128 | MSG_("use PgUp/PgDown for crawling commands history.");
|
Nicolas Jager | 4569bf5 | 2016-11-03 11:13:47 -0400 | [diff] [blame] | 129 | MSG_("getCallsList, switchDebug, killCall [callId, -all], getAccountInfo, getContactsList, placeCall [contact name]");
|
atraczyk | 61b2842 | 2016-08-24 09:25:59 -0400 | [diff] [blame] | 130 | return;
|
| 131 | }
|
Nicolas Jager | 4569bf5 | 2016-11-03 11:13:47 -0400 | [diff] [blame] | 132 | else if (input == "getCallsList") {
|
| 133 | RingD::instance->getCallsList();
|
| 134 | return;
|
| 135 | }
|
| 136 | else if (input == "switchDebug") {
|
| 137 | MSG_(">> switching dameon debug output");
|
| 138 | RingD::instance->switchDebug();
|
| 139 | return;
|
| 140 | }
|
| 141 | else if (input == "killCall") {
|
| 142 | if (parameter1.empty()) {
|
| 143 | MSG_("callId missing");
|
| 144 | return;
|
| 145 | }
|
| 146 | RingD::instance->killCall(Utils::toPlatformString(parameter1));
|
| 147 | return;
|
| 148 | }
|
| 149 | else if (input == "getAccountInfo") {
|
| 150 | auto id = AccountListItemsViewModel::instance->_selectedItem->_account->accountID_;
|
| 151 | MSG_("id : "+Utils::toString(id));
|
| 152 | return;
|
| 153 | }
|
atraczyk | 61b2842 | 2016-08-24 09:25:59 -0400 | [diff] [blame] | 154 |
|
Nicolas Jager | 4569bf5 | 2016-11-03 11:13:47 -0400 | [diff] [blame] | 155 | MSG_(">> error, command \'" + input + "\' not found");
|
atraczyk | 61b2842 | 2016-08-24 09:25:59 -0400 | [diff] [blame] | 156 | }
|
| 157 |
|
| 158 | void RingConsolePanel::addCommandToHistory()
|
| 159 | {
|
| 160 | historyCmds.Append(_tBoxDbg_->Text);
|
Nicolas Jager | 32ed1a2 | 2016-08-17 08:36:02 -0400 | [diff] [blame] | 161 | }
|