/patchexchangegui.cpp

http://ewitool.googlecode.com/ · 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. #include <QMessageBox>
  21. #include <QSettings>
  22. #include "patchexchangegui.h"
  23. patchExchangeGUI::patchExchangeGUI(Clipboard *clipbrd, patchExchange *main_epx, QWidget *parent )
  24. : QWidget(parent)
  25. {
  26. setupUi( this );
  27. QSettings settings( "EWItool", "EWItool" );
  28. url = settings.value( "PatchExchange/Server" ).toString();
  29. epx = main_epx;
  30. // data returns
  31. connect( epx, SIGNAL( dropdownData( QStringList ) ), this, SLOT( populateEPXtab( QStringList ) ) );
  32. connect( epx, SIGNAL( insertResponse( QString ) ), epx, SLOT( exchangeClipboardResponse( QString ) ) );
  33. connect( epx, SIGNAL( queryResponse( QString ) ), this, SLOT( epxQueryResults( QString ) ) );
  34. connect( epx, SIGNAL( detailsResponse( QString ) ), this, SLOT( epxDetailsResults( QString ) ) );
  35. connect( epx, SIGNAL( deleteResponse( QString ) ) , this, SLOT( deleteResults( QString ) ) );
  36. connect( epx, SIGNAL( statsResponse( QString ) ) , this, SLOT( epxStatsResults( QString ) ) );
  37. epx->getDropdowns( url );
  38. epx->getStats( url );
  39. clipboard = clipbrd;
  40. }
  41. patchExchangeGUI::~patchExchangeGUI()
  42. {
  43. }
  44. /**
  45. * The data for EPX have arrived - populate the tab
  46. */
  47. void patchExchangeGUI::populateEPXtab( QStringList dropdown_data ) {
  48. QStringList sl = dropdown_data.at( 0 ).split( "," );
  49. type_comboBox->addItems( sl );
  50. sl = dropdown_data.at( 1 ).split( "," );
  51. contributor_comboBox->addItems( sl );
  52. sl = dropdown_data.at( 2 ).split( "," );
  53. origin_comboBox->addItems( sl );
  54. // widgets
  55. connect( epxQuery_pushButton, SIGNAL( clicked() ), this, SLOT( epxQuery() ) );
  56. connect( epxDelete_pushButton, SIGNAL( clicked() ), this, SLOT( epxDelete() ) );
  57. connect( epxCopy_pushButton, SIGNAL( clicked() ), this, SLOT( epxCopy() ) );
  58. connect( results_listWidget, SIGNAL( itemSelectionChanged() ), this, SLOT( epxChosen() ) ) ;
  59. //epx_tab->setEnabled( true );
  60. this->setEnabled( true );
  61. }
  62. void patchExchangeGUI::epxQuery() {
  63. QSettings *settings = new QSettings( "EWItool", "EWItool" );
  64. epx->query( settings->value( "PatchExchange/Server" ).toString(),
  65. settings->value( "PatchExchange/UserID" ).toString(),
  66. settings->value( "PatchExchange/Password" ).toString(),
  67. type_comboBox->currentText(),
  68. since_comboBox->currentText(),
  69. contributor_comboBox->currentText(),
  70. origin_comboBox->currentText(),
  71. tags_lineEdit->text() );
  72. epxCopy_pushButton->setEnabled( false );
  73. epxDelete_pushButton->setEnabled( false );
  74. }
  75. void patchExchangeGUI::epxQueryResults( QString patch_list ) {
  76. int id;
  77. results_listWidget->clear();
  78. epx_ids.clear();
  79. QStringList pl = patch_list.split( "\n" );
  80. for (int i = 0; i < pl.size(); i++ ) {
  81. results_listWidget->addItem( pl.at(i).left( pl.at(i).lastIndexOf( "," ) ) );
  82. id = pl.at(i).mid( pl.at(i).lastIndexOf( "," ) + 1 ).toInt();
  83. epx_ids.append( id );
  84. }
  85. }
  86. void patchExchangeGUI::epxStatsResults( QString stats_list ) {
  87. QStringList sl = stats_list.split( "\n" );
  88. users_label->setText( sl.at( 0 ) );
  89. patches_label->setText( sl.at( 1 ) );
  90. contributors_label->setText( sl.at( 2 ) );
  91. origins_label->setText( sl.at( 3 ) );
  92. access_label->setText( sl.at( 4 ) );
  93. }
  94. void patchExchangeGUI::epxChosen() {
  95. int id;
  96. QSettings *settings = new QSettings( "EWItool", "EWItool" );
  97. id = epx_ids.at( results_listWidget->currentRow() );
  98. epx->getDetails( settings->value( "PatchExchange/Server" ).toString(),
  99. settings->value( "PatchExchange/UserID" ).toString(),
  100. settings->value( "PatchExchange/Password" ).toString(),
  101. id
  102. );
  103. }
  104. void patchExchangeGUI::epxDetailsResults( QString details ) {
  105. if (details.contains( "," )) {
  106. QStringList parms = details.split( "," ); //////////// this needs fixing ***
  107. name_label->setText( parms.at( 0 ) );
  108. contributor_label->setText( parms.at( 1 ) );
  109. originator_label->setText( parms.at( 2 ) );
  110. epx_hex_patch = parms.at( 3 );
  111. type_label->setText( parms.at( 4 ) );
  112. desc_label->setText( parms.at( 5 ) );
  113. added_label->setText( parms.at( 6 ) );
  114. if (parms.at(7) == "f")
  115. private_label->setText( "public" );
  116. else
  117. private_label->setText( "private" );
  118. tags_label->setText( parms.at( 8 ) );
  119. epxCopy_pushButton->setEnabled( true );
  120. epxDelete_pushButton->setEnabled( true );
  121. }
  122. }
  123. void patchExchangeGUI::epxDelete() {
  124. if ( results_listWidget->currentRow() >= 0 ) {
  125. QSettings *settings = new QSettings( "EWItool", "EWItool" );
  126. int id = epx_ids.at( results_listWidget->currentRow() );
  127. epx->deletePatch( settings->value( "PatchExchange/Server" ).toString(),
  128. settings->value( "PatchExchange/UserID" ).toString(),
  129. settings->value( "PatchExchange/Password" ).toString(),
  130. id
  131. );
  132. epx_ids.removeAt( id );
  133. name_label->clear();
  134. contributor_label->clear();
  135. originator_label->clear();
  136. type_label->clear();
  137. desc_label->clear();
  138. tags_label->clear();
  139. added_label->clear();
  140. epxCopy_pushButton->setEnabled( false );
  141. epxDelete_pushButton->setEnabled( false );
  142. // force a re-query
  143. epxQuery();
  144. }
  145. }
  146. void patchExchangeGUI::deleteResults( QString r ) {
  147. epxQuery();
  148. epx->getStats( url );
  149. }
  150. void patchExchangeGUI::epxCopy() {
  151. patch_t new_patch;
  152. new_patch = ewi4000sPatch::dehexify( epx_hex_patch, false );
  153. clipboard->appendItem( new_patch );
  154. }