/patchexchangegui.cpp
C++ | 197 lines | 128 code | 43 blank | 26 comment | 5 complexity | 283fea622bd8b9a508c1cf4153717051 MD5 | raw file
1/*************************************************************************** 2 * Copyright (C) 2008 by Steve Merrony * 3 * steve@brahma * 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, write to the * 17 * Free Software Foundation, Inc., * 18 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * 19 ***************************************************************************/ 20 21#include <QMessageBox> 22#include <QSettings> 23 24#include "patchexchangegui.h" 25 26patchExchangeGUI::patchExchangeGUI(Clipboard *clipbrd, patchExchange *main_epx, QWidget *parent ) 27 : QWidget(parent) 28{ 29 setupUi( this ); 30 31 QSettings settings( "EWItool", "EWItool" ); 32 url = settings.value( "PatchExchange/Server" ).toString(); 33 epx = main_epx; 34 // data returns 35 connect( epx, SIGNAL( dropdownData( QStringList ) ), this, SLOT( populateEPXtab( QStringList ) ) ); 36 connect( epx, SIGNAL( insertResponse( QString ) ), epx, SLOT( exchangeClipboardResponse( QString ) ) ); 37 connect( epx, SIGNAL( queryResponse( QString ) ), this, SLOT( epxQueryResults( QString ) ) ); 38 connect( epx, SIGNAL( detailsResponse( QString ) ), this, SLOT( epxDetailsResults( QString ) ) ); 39 connect( epx, SIGNAL( deleteResponse( QString ) ) , this, SLOT( deleteResults( QString ) ) ); 40 connect( epx, SIGNAL( statsResponse( QString ) ) , this, SLOT( epxStatsResults( QString ) ) ); 41 epx->getDropdowns( url ); 42 epx->getStats( url ); 43 44 clipboard = clipbrd; 45} 46 47patchExchangeGUI::~patchExchangeGUI() 48{ 49} 50 51/** 52 * The data for EPX have arrived - populate the tab 53 */ 54void patchExchangeGUI::populateEPXtab( QStringList dropdown_data ) { 55 56 QStringList sl = dropdown_data.at( 0 ).split( "," ); 57 type_comboBox->addItems( sl ); 58 sl = dropdown_data.at( 1 ).split( "," ); 59 contributor_comboBox->addItems( sl ); 60 sl = dropdown_data.at( 2 ).split( "," ); 61 origin_comboBox->addItems( sl ); 62 // widgets 63 connect( epxQuery_pushButton, SIGNAL( clicked() ), this, SLOT( epxQuery() ) ); 64 connect( epxDelete_pushButton, SIGNAL( clicked() ), this, SLOT( epxDelete() ) ); 65 connect( epxCopy_pushButton, SIGNAL( clicked() ), this, SLOT( epxCopy() ) ); 66 connect( results_listWidget, SIGNAL( itemSelectionChanged() ), this, SLOT( epxChosen() ) ) ; 67 68 //epx_tab->setEnabled( true ); 69 this->setEnabled( true ); 70} 71 72 73void patchExchangeGUI::epxQuery() { 74 75 QSettings *settings = new QSettings( "EWItool", "EWItool" ); 76 epx->query( settings->value( "PatchExchange/Server" ).toString(), 77 settings->value( "PatchExchange/UserID" ).toString(), 78 settings->value( "PatchExchange/Password" ).toString(), 79 type_comboBox->currentText(), 80 since_comboBox->currentText(), 81 contributor_comboBox->currentText(), 82 origin_comboBox->currentText(), 83 tags_lineEdit->text() ); 84 85 epxCopy_pushButton->setEnabled( false ); 86 epxDelete_pushButton->setEnabled( false ); 87} 88 89void patchExchangeGUI::epxQueryResults( QString patch_list ) { 90 91 int id; 92 93 results_listWidget->clear(); 94 epx_ids.clear(); 95 96 QStringList pl = patch_list.split( "\n" ); 97 for (int i = 0; i < pl.size(); i++ ) { 98 results_listWidget->addItem( pl.at(i).left( pl.at(i).lastIndexOf( "," ) ) ); 99 id = pl.at(i).mid( pl.at(i).lastIndexOf( "," ) + 1 ).toInt(); 100 epx_ids.append( id ); 101 } 102} 103 104void patchExchangeGUI::epxStatsResults( QString stats_list ) { 105 106 QStringList sl = stats_list.split( "\n" ); 107 users_label->setText( sl.at( 0 ) ); 108 patches_label->setText( sl.at( 1 ) ); 109 contributors_label->setText( sl.at( 2 ) ); 110 origins_label->setText( sl.at( 3 ) ); 111 access_label->setText( sl.at( 4 ) ); 112} 113 114void patchExchangeGUI::epxChosen() { 115 116 int id; 117 118 QSettings *settings = new QSettings( "EWItool", "EWItool" ); 119 id = epx_ids.at( results_listWidget->currentRow() ); 120 epx->getDetails( settings->value( "PatchExchange/Server" ).toString(), 121 settings->value( "PatchExchange/UserID" ).toString(), 122 settings->value( "PatchExchange/Password" ).toString(), 123 id 124 ); 125} 126 127void patchExchangeGUI::epxDetailsResults( QString details ) { 128 129 if (details.contains( "," )) { 130 QStringList parms = details.split( "," ); //////////// this needs fixing *** 131 name_label->setText( parms.at( 0 ) ); 132 contributor_label->setText( parms.at( 1 ) ); 133 originator_label->setText( parms.at( 2 ) ); 134 epx_hex_patch = parms.at( 3 ); 135 type_label->setText( parms.at( 4 ) ); 136 desc_label->setText( parms.at( 5 ) ); 137 added_label->setText( parms.at( 6 ) ); 138 if (parms.at(7) == "f") 139 private_label->setText( "public" ); 140 else 141 private_label->setText( "private" ); 142 tags_label->setText( parms.at( 8 ) ); 143 144 epxCopy_pushButton->setEnabled( true ); 145 epxDelete_pushButton->setEnabled( true ); 146 } 147} 148 149void patchExchangeGUI::epxDelete() { 150 151 if ( results_listWidget->currentRow() >= 0 ) { 152 153 QSettings *settings = new QSettings( "EWItool", "EWItool" ); 154 int id = epx_ids.at( results_listWidget->currentRow() ); 155 epx->deletePatch( settings->value( "PatchExchange/Server" ).toString(), 156 settings->value( "PatchExchange/UserID" ).toString(), 157 settings->value( "PatchExchange/Password" ).toString(), 158 id 159 ); 160 epx_ids.removeAt( id ); 161 162 name_label->clear(); 163 contributor_label->clear(); 164 originator_label->clear(); 165 type_label->clear(); 166 desc_label->clear(); 167 tags_label->clear(); 168 added_label->clear(); 169 epxCopy_pushButton->setEnabled( false ); 170 epxDelete_pushButton->setEnabled( false ); 171 172 // force a re-query 173 epxQuery(); 174 175 } 176} 177 178void patchExchangeGUI::deleteResults( QString r ) { 179 180 epxQuery(); 181 epx->getStats( url ); 182} 183 184void patchExchangeGUI::epxCopy() { 185 186 patch_t new_patch; 187 188 new_patch = ewi4000sPatch::dehexify( epx_hex_patch, false ); 189 190 clipboard->appendItem( new_patch ); 191} 192 193 194 195 196 197