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) {
|
| 34 | output(message);
|
| 35 | });
|
| 36 | }
|
| 37 |
|
| 38 | void
|
| 39 | RingConsolePanel::output(Platform::String^ message)
|
| 40 | {
|
| 41 | try {
|
| 42 | Run^ inlineText = ref new Run();
|
| 43 | inlineText->Text = message;
|
| 44 | Paragraph^ paragraph = ref new Paragraph();
|
| 45 | paragraph->Inlines->Append(inlineText);
|
| 46 | _debugWindowOutput_->Blocks->Append(paragraph);
|
| 47 | _scrollView_->UpdateLayout();
|
| 48 | _scrollView_->ScrollToVerticalOffset(_scrollView_->ScrollableHeight);
|
| 49 | }
|
| 50 | catch (Platform::Exception^ e) {
|
| 51 | return;
|
| 52 | }
|
| 53 | }
|
| 54 |
|
| 55 | void RingConsolePanel::_btnSendDbgCmd__Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e)
|
| 56 | {
|
| 57 | sendCommand();
|
| 58 | }
|
| 59 |
|
| 60 |
|
| 61 | void RingConsolePanel::_sendDbgCmd__KeyDown(Platform::Object^ sender, Windows::UI::Xaml::Input::KeyRoutedEventArgs^ e)
|
| 62 | {
|
| 63 | if (e->Key == Windows::System::VirtualKey::Enter && _tBoxDbg_->Text != "") {
|
| 64 | sendCommand();
|
| 65 | }
|
| 66 | else if (e->Key == Windows::System::VirtualKey::PageUp) {
|
| 67 |
|
| 68 | if (historyLevel < 1)
|
| 69 | return;
|
| 70 | if (historyLevel == historyCmds.Size)
|
| 71 | currentCmd = _tBoxDbg_->Text;
|
| 72 | historyLevel--;
|
| 73 | _tBoxDbg_->Text = historyCmds.GetAt(historyLevel);
|
| 74 |
|
| 75 | }
|
| 76 | else if (e->Key == Windows::System::VirtualKey::PageDown) {
|
| 77 | if (historyLevel < historyCmds.Size) {
|
| 78 | _tBoxDbg_->Text = historyCmds.GetAt(historyLevel);
|
| 79 | historyLevel++;
|
| 80 |
|
| 81 | }
|
| 82 | else {
|
| 83 | _tBoxDbg_->Text = currentCmd;
|
| 84 | }
|
| 85 | return;
|
| 86 | }
|
| 87 | }
|
| 88 |
|
| 89 | /*\ ADD EACH NEW COMMAND TO THE HELP LIST \*/
|
| 90 | void RingConsolePanel::sendCommand()
|
| 91 | {
|
Nicolas Jager | 4569bf5 | 2016-11-03 11:13:47 -0400 | [diff] [blame] | 92 | auto inputConst_str = Utils::toString(_tBoxDbg_->Text);
|
| 93 | if (inputConst_str.empty())
|
| 94 | return;
|
| 95 |
|
| 96 | auto inputConst_cstr = inputConst_str.c_str();
|
| 97 | char* input_cstr = _strdup(inputConst_cstr); // full string
|
| 98 | char* input_cstr_nextToken; // tokenized string
|
| 99 | char* cmd_cstr = strtok_s(input_cstr, " ", &input_cstr_nextToken);
|
| 100 | char* parameter1_cstr = strtok_s(input_cstr_nextToken, " ", &input_cstr_nextToken);
|
| 101 | // parameter2...
|
| 102 |
|
| 103 | if (!cmd_cstr)
|
| 104 | return;
|
| 105 |
|
| 106 | std::string input(cmd_cstr);
|
| 107 | std::string parameter1;
|
| 108 |
|
| 109 | if (parameter1_cstr)
|
| 110 | parameter1 = parameter1_cstr;
|
| 111 |
|
| 112 | free(input_cstr);
|
| 113 | free(input_cstr_nextToken);
|
| 114 | //free((char*)inputConst_cstr);
|
| 115 |
|
atraczyk | 61b2842 | 2016-08-24 09:25:59 -0400 | [diff] [blame] | 116 | addCommandToHistory();
|
| 117 | historyLevel++;
|
| 118 | _tBoxDbg_->Text = "";
|
| 119 | currentCmd = "";
|
| 120 | historyLevel = historyCmds.Size;
|
| 121 |
|
Nicolas Jager | 4569bf5 | 2016-11-03 11:13:47 -0400 | [diff] [blame] | 122 | if (input == "help") {
|
atraczyk | 61b2842 | 2016-08-24 09:25:59 -0400 | [diff] [blame] | 123 | MSG_(">> Help :");
|
| 124 | MSG_("use PgUp/PgDown for crawling commands history.");
|
Nicolas Jager | 4569bf5 | 2016-11-03 11:13:47 -0400 | [diff] [blame] | 125 | MSG_("getCallsList, switchDebug, killCall [callId, -all], getAccountInfo, getContactsList, placeCall [contact name]");
|
atraczyk | 61b2842 | 2016-08-24 09:25:59 -0400 | [diff] [blame] | 126 | return;
|
| 127 | }
|
Nicolas Jager | 4569bf5 | 2016-11-03 11:13:47 -0400 | [diff] [blame] | 128 | else if (input == "getCallsList") {
|
| 129 | RingD::instance->getCallsList();
|
| 130 | return;
|
| 131 | }
|
| 132 | else if (input == "switchDebug") {
|
| 133 | MSG_(">> switching dameon debug output");
|
| 134 | RingD::instance->switchDebug();
|
| 135 | return;
|
| 136 | }
|
| 137 | else if (input == "killCall") {
|
| 138 | if (parameter1.empty()) {
|
| 139 | MSG_("callId missing");
|
| 140 | return;
|
| 141 | }
|
| 142 | RingD::instance->killCall(Utils::toPlatformString(parameter1));
|
| 143 | return;
|
| 144 | }
|
| 145 | else if (input == "getAccountInfo") {
|
| 146 | auto id = AccountListItemsViewModel::instance->_selectedItem->_account->accountID_;
|
| 147 | MSG_("id : "+Utils::toString(id));
|
| 148 | return;
|
| 149 | }
|
| 150 | else if (input == "getContactsList") {
|
atraczyk | 4691003 | 2017-03-08 17:57:01 -0500 | [diff] [blame^] | 151 | auto list = ContactListModel::instance->contactsList;
|
Nicolas Jager | 4569bf5 | 2016-11-03 11:13:47 -0400 | [diff] [blame] | 152 | MSG_("list of calls returned by the daemon :");
|
| 153 | for (auto contact : list) {
|
Nicolas Jager | 7f34b77 | 2016-12-09 12:25:25 -0500 | [diff] [blame] | 154 | MSG_("name : " + Utils::toString(contact->_name));
|
Nicolas Jager | 4569bf5 | 2016-11-03 11:13:47 -0400 | [diff] [blame] | 155 | MSG_("ringId : " + Utils::toString(contact->ringID_));
|
| 156 | }
|
| 157 | return;
|
| 158 | }
|
| 159 | else if (input == "placeCall") {
|
| 160 | if (parameter1.empty()) {
|
| 161 | MSG_("contact name missing");
|
| 162 | return;
|
| 163 | }
|
atraczyk | 4691003 | 2017-03-08 17:57:01 -0500 | [diff] [blame^] | 164 | auto contact = ContactListModel::instance->findContactByName(Utils::toPlatformString(parameter1));
|
Nicolas Jager | 4569bf5 | 2016-11-03 11:13:47 -0400 | [diff] [blame] | 165 | if (!contact) {
|
| 166 | MSG_("contact "+parameter1+" not found");
|
| 167 | return;
|
| 168 | }
|
| 169 | RingD::instance->placeCall(contact);
|
| 170 | }
|
atraczyk | 61b2842 | 2016-08-24 09:25:59 -0400 | [diff] [blame] | 171 |
|
Nicolas Jager | 4569bf5 | 2016-11-03 11:13:47 -0400 | [diff] [blame] | 172 | MSG_(">> error, command \'" + input + "\' not found");
|
atraczyk | 61b2842 | 2016-08-24 09:25:59 -0400 | [diff] [blame] | 173 | }
|
| 174 |
|
| 175 | void RingConsolePanel::addCommandToHistory()
|
| 176 | {
|
| 177 | historyCmds.Append(_tBoxDbg_->Text);
|
Nicolas Jager | 32ed1a2 | 2016-08-17 08:36:02 -0400 | [diff] [blame] | 178 | }
|