source: src-qt4/pc-softwaremanager/mainUI.cpp @ ae5a5d8

releng/10.0.1releng/10.0.2
Last change on this file since ae5a5d8 was ae5a5d8, checked in by Ken Moore <ken@…>, 5 months ago

Make sure that with actual PBI installed list changes, the browser app page does a full refresh if it is visible, rather than just updating the download button.

  • Property mode set to 100644
File size: 46.3 KB
Line 
1/***************************************************************************
2 *   Copyright (C) 2011 - iXsystems                                       *
3 *   kris@pcbsd.org  *
4 *   tim@pcbsd.org   *
5 *   ken@pcbsd.org   *
6 *                                                                         *
7 *   Permission is hereby granted, free of charge, to any person obtaining *
8 *   a copy of this software and associated documentation files (the       *
9 *   "Software"), to deal in the Software without restriction, including   *
10 *   without limitation the rights to use, copy, modify, merge, publish,   *
11 *   distribute, sublicense, and/or sell copies of the Software, and to    *
12 *   permit persons to whom the Software is furnished to do so, subject to *
13 *   the following conditions:                                             *
14 *                                                                         *
15 *   The above copyright notice and this permission notice shall be        *
16 *   included in all copies or substantial portions of the Software.       *
17 *                                                                         *
18 *   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,       *
19 *   EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF    *
20 *   MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
21 *   IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR     *
22 *   OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, *
23 *   ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR *
24 *   OTHER DEALINGS IN THE SOFTWARE.                                       *
25 ***************************************************************************/
26#include "mainUI.h"
27#include "ui_mainUI.h"
28
29MainUI::MainUI(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainUI){
30  //initialization function
31  ui->setupUi(this); //load the Qt-Designer file
32  defaultIcon = ":/application.png";
33  statusLabel = new QLabel();
34  ui->statusbar->addWidget(statusLabel);
35}
36
37void MainUI::setWardenMode(QString dir, QString ip){
38  wardenDir = dir; wardenIP = ip;
39}
40
41void MainUI::ProgramInit()
42{ 
43   qDebug("Application starting...");
44   //Initial Checks
45     bool wardenMode = !wardenDir.isEmpty();
46     bool ok = Extras::checkUser(wardenMode);
47     if(!ok && wardenMode){  //Not root
48       QMessageBox::information( this, tr("Error!"), tr("The AppCafe must be run as root when in Warden compatibility mode") );
49       close();     
50     }else if( !ok && !wardenMode){
51       QMessageBox::information( this, tr("Error!"), tr("The AppCafe must be started with user permissions!")+"\n"+tr("The user must also be a part of the \"operator\" group") );
52       close();
53     }
54   
55   //Initialize the backend worker class
56   //qDebug() << "Initialize Backend";
57   PBI = new PBIBackend();
58     if(wardenMode){ PBI->setWardenMode(wardenDir, wardenIP); }
59     
60   //Initialize the Installed tab
61   //qDebug() << "Initialize Installed Tab";
62   initializeInstalledTab();
63   //Initialize the PBI Browser
64   //qDebug() << "Initialize Browser Tab";
65   initializeBrowserTab();
66   
67   //Now startup the backend
68   //qDebug() << "Startup Backend";
69     connect(PBI,SIGNAL(LocalPBIChanges()),this,SLOT(slotRefreshInstallTab()) );
70     connect(PBI,SIGNAL(PBIStatusChange(QString)),this,SLOT(slotPBIStatusUpdate(QString)) );
71     connect(PBI,SIGNAL(RepositoryInfoReady()),this,SLOT(slotEnableBrowser()) );
72     connect(PBI,SIGNAL(NoRepoAvailable()),this,SLOT(slotDisableBrowser()) );
73     connect(PBI,SIGNAL(SearchComplete(QStringList,QStringList)),this,SLOT(slotShowSearchResults(QStringList, QStringList)) );
74     connect(PBI,SIGNAL(SimilarFound(QStringList)),this,SLOT(slotShowSimilarApps(QStringList)) );
75     connect(PBI,SIGNAL(Error(QString,QString,QStringList)),this,SLOT(slotDisplayError(QString,QString,QStringList)) );
76     PBI->start();
77
78   //Make sure we start on the installed tab
79   ui->tabWidget->setCurrentWidget(ui->tab_installed);
80   ui->stackedWidget->setCurrentWidget(ui->page_install_list);
81}
82
83void MainUI::slotSingleInstance(){
84  this->raise();
85  this->showNormal();
86  this->activateWindow();
87}
88
89void MainUI::closeEvent(QCloseEvent *event){
90  bool safe = PBI->safeToQuit();
91  if(!safe){
92    //Verify that they want to continue
93    QMessageBox::StandardButton button = QMessageBox::warning(this, tr("AppCafe Processes Running"), tr("The AppCafe currently has actions pending. Do you want to cancel all running processes and quit anyway?"), QMessageBox::Yes | QMessageBox::Cancel,QMessageBox::Cancel);
94    if(button == QMessageBox::Yes){ //close down
95      PBI->cancelActions( PBI->installedList() ); //close down safely
96    }else{
97      event->ignore();
98      return;
99    }
100  }
101  this->close();
102}
103// ========================
104// ===== MENU OPTIONS =====
105// ========================
106void MainUI::on_actionImport_PBI_List_triggered(){
107  QString file = QFileDialog::getOpenFileName( this, tr("Import PBI File List"), QDir::homePath(), tr("PBI List (*.pbilist)"));
108  if(file.isEmpty()){ return; } //action cancelled
109  bool ok = PBI->importPbiListFromFile(file);
110  if(!ok){ qDebug() << QMessageBox::warning(this,tr("Import Error"),tr("There was an error importing the PBI list")+"\n"+tr("Please make sure that the file has not been corrupted and try again")); }
111}
112
113void MainUI::on_actionExport_PBI_List_triggered(){
114  QString file = QFileDialog::getSaveFileName( this, tr("Export PBI File List"), QDir::homePath()+"/exportfile.pbilist", tr("PBI List (*.pbilist)"));
115  if(file.isEmpty()){ return; } //action cancelled
116  bool ok = PBI->exportPbiListToFile(file);
117  if(!ok){ qDebug() << QMessageBox::warning(this,tr("Export Error"),tr("There was an error exporting the PBI list")+"\n"+tr("Please make sure that you have the proper directory permissions and try again")); }
118}
119
120void MainUI::on_actionQuit_triggered(){
121  this->close();
122}
123
124void MainUI::on_actionAppCafe_Settings_triggered(){
125  PBI->openConfigurationDialog();
126}
127
128void MainUI::on_actionInstall_From_File_triggered(){
129  QStringList files = QFileDialog::getOpenFileNames(this, tr("Install PBI"), QDir::homePath(), tr("PBI Application (*.pbi)") );
130  if(files.isEmpty()){ return; } //cancelled
131  //Verify that they want to install these applications
132  QStringList names;
133  for(int i=0; i<files.length(); i++){ names << files[i].section("/",-1); }
134  names.sort();
135  if( QMessageBox::Yes == QMessageBox::question(this, tr("Verify Installation"), tr("Are you ready to begin installing these PBI's?")+"\n"+tr("NOTE: You will need to manually add desktop/menu icons through the AppCafe afterwards.")+"\n\n"+names.join("\n"), QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes) ){
136    //This might take a while, so don't allow the user to run this action again until it is done (thread safe though)
137    ui->actionInstall_From_File->setEnabled(false);
138    PBI->installPBIFromFile(files);
139    ui->actionInstall_From_File->setEnabled(true);
140  }
141}
142
143// =========================
144// ===== INSTALLED TAB =====
145// =========================
146void MainUI::initializeInstalledTab(){
147  //Setup the action menu for installed applications
148  actionMenu = new QMenu();
149    actionMenu->addAction( QIcon(":icons/view-refresh.png"), tr("Update"), this, SLOT(slotActionUpdate()) );
150    actionMenu->addSeparator();
151    QMenu *dmenu = actionMenu->addMenu( QIcon(":icons/xdg_desktop.png"), tr("Desktop Icons"));
152      dmenu->addAction( QIcon(":icons/add.png"),tr("Add"),this,SLOT(slotActionAddDesktop()) );
153      dmenu->addAction( QIcon(":icons/remove.png"),tr("Remove"),this,SLOT(slotActionRemoveDesktop()) );
154    QMenu *mmenu = actionMenu->addMenu( QIcon(":icons/xdg_menu.png"), tr("Menu Icons"));
155      mmenu->addAction( QIcon(":icons/add.png"),tr("Add"),this,SLOT(slotActionAddMenu()) );
156      mmenu->addAction( QIcon(":icons/remove.png"),tr("Remove"),this,SLOT(slotActionRemoveMenu()) ); 
157      mmenu->addAction( QIcon(":icons/add-root.png"),tr("Add (All Users)"),this,SLOT(slotActionAddMenuAll()) );
158    QMenu *pmenu = actionMenu->addMenu( QIcon(":icons/xdg_paths.png"), tr("Path Links"));
159      pmenu->addAction( QIcon(":icons/add.png"),tr("Add"),this,SLOT(slotActionAddPath()) );
160      pmenu->addAction( QIcon(":icons/remove.png"),tr("Remove"),this,SLOT(slotActionRemovePath()) ); 
161      pmenu->addAction( QIcon(":icons/add-root.png"),tr("Add (All Users)"),this,SLOT(slotActionAddPathAll()) );
162    QMenu *fmenu = actionMenu->addMenu( QIcon(":icons/xdg_mime.png"), tr("File Associations"));
163      fmenu->addAction( QIcon(":icons/add.png"),tr("Add"),this,SLOT(slotActionAddMime()) );
164      fmenu->addAction( QIcon(":icons/remove.png"),tr("Remove"),this,SLOT(slotActionRemoveMime()) ); 
165      fmenu->addAction( QIcon(":icons/add-root.png"),tr("Add (All Users)"),this,SLOT(slotActionAddMimeAll()) );
166    actionMenu->addSeparator();
167    actionMenu->addAction( QIcon(":icons/remove.png"), tr("Uninstall"), this, SLOT(slotActionRemove()) );
168    actionMenu->addSeparator();
169    actionMenu->addAction( QIcon(":icons/dialog-cancel.png"), tr("Cancel Actions"), this, SLOT(slotActionCancel()) );
170  //Setup the binary menu for installed applications
171  appBinMenu = new QMenu();
172  ui->tool_install_startApp->setMenu(appBinMenu);
173    connect(appBinMenu, SIGNAL(triggered(QAction*)), this, SLOT(slotStartApp(QAction*)) );
174  //Now setup the action button
175  ui->tool_install_performaction->setMenu(actionMenu);
176  ui->tool_install_performaction->setPopupMode(QToolButton::InstantPopup);
177  //Now setup any defaults for the installed tab
178  ui->tree_install_apps->setIconSize(QSize(22,22));
179  connect(ui->tree_install_apps, SIGNAL(itemClicked(QTreeWidgetItem*, int)), this, SLOT(slotCheckSelectedItems()) );
180  slotRefreshInstallTab();
181  qDebug() << "Detailed shortcuts button not implemented yet";
182  ui->tool_install_shortcuts->setEnabled(false);
183}
184
185void MainUI::formatInstalledItemDisplay(QTreeWidgetItem *item){
186  //simplification function for filling the tree widget item with the appropriate information about the PBI
187  QString ID = item->whatsThis(0);
188  if(item->text(0).isEmpty()){  //new entry - get everything
189    QStringList vals; vals <<"name"<<"version"<<"status"; //same as column order
190    if(!vals.isEmpty()){
191      vals = PBI->PBIInfo(ID, vals);
192      for(int i=0; i<vals.length(); i++){ item->setText(i,vals[i]); }
193      QString icon = PBI->PBIInfo(ID, QStringList("icon")).join("");
194        //Load a default icon if none found
195      if(icon.isEmpty()){ icon = defaultIcon; }
196      item->setIcon(0,QIcon(icon) );
197      item->setCheckState(0,Qt::Unchecked);
198    }
199  }else{ // Just update the necesary info
200    QStringList vals; vals << "version" << "status";
201    vals = PBI->PBIInfo(ID,vals);
202    if(!vals.isEmpty()){ item->setText(1,vals[0]); item->setText(2,vals[1]); }
203  }
204}
205
206QStringList MainUI::getCheckedItems(){
207  //Return the pbiID's of all the checked items
208  QStringList output;
209  for(int i=0; i<ui->tree_install_apps->topLevelItemCount(); i++){
210    if(ui->tree_install_apps->topLevelItem(i)->checkState(0) == Qt::Checked){
211      output << ui->tree_install_apps->topLevelItem(i)->whatsThis(0);
212    }
213  }
214  //If no items checked, use the item that is selected instead
215  if(output.isEmpty()){
216    //Make sure that an item is selected
217    if(ui->tree_install_apps->topLevelItemCount() >0){
218      output << ui->tree_install_apps->currentItem()->whatsThis(0); 
219    }
220  }
221  return output;       
222}
223
224// === SLOTS ===
225void MainUI::slotRefreshInstallTab(){
226  //Update the list of installed PBI's w/o clearing the list (loses selections)
227   //Get the list we need (in order)
228  QStringList installList = PBI->installedList();
229  installList.sort(); //sort in ascending order
230   //Get the list we have now
231  QStringList cList;
232  for(int i=0; i<ui->tree_install_apps->topLevelItemCount(); i++){
233    cList << ui->tree_install_apps->topLevelItem(i)->whatsThis(0);
234  }
235  //Quick finish if no items installed
236  if(installList.isEmpty()){
237    ui->tree_install_apps->clear();
238  }else{
239    //Now make adjustments as necessary
240    for(int i=0; i<installList.length(); i++){
241      //Detemine what action should be done with this item location
242      int todo = 0; //0=insert new item, 1=update current item, 2=remove current item
243      if(i < cList.length()){
244        if(installList[i] == cList[i]){ todo=1; }
245        else if( installList.contains(cList[i]) && !cList.contains(installList[i]) ){ todo=0; } //new item to be inserted here
246        else if( !installList.contains(cList[i]) ){ todo=2; } //current item in this location should be removed
247      }
248      //Now perform the action on this location
249      if(todo==0){ 
250        //insert new item
251        QTreeWidgetItem *item = new QTreeWidgetItem; //create the item
252        item->setWhatsThis(0,installList[i]);
253        //Now format the display
254        formatInstalledItemDisplay(item);
255        if(item->text(0).isEmpty()){
256          //Do not put empty items into the display
257          delete item;
258        }else{
259          //Now insert this item onto the list
260          ui->tree_install_apps->insertTopLevelItem(i,item);
261          cList.insert(i,installList[i]); //reflect this inclusion into the current list
262        }
263      }else if(todo==1){
264        //Update current item
265        formatInstalledItemDisplay( ui->tree_install_apps->topLevelItem(i) );
266      }else{
267        //Remove current item
268        ui->tree_install_apps->takeTopLevelItem(i);
269        cList.removeAt(i); //reflect the change to the current list
270        i--; //Re-check the item that should be in this location
271      }
272    }
273    //Now makesure that there are no extra items at the end
274    int il = installList.length();
275    while(il < cList.length()){
276      ui->tree_install_apps->takeTopLevelItem(il);
277      cList.removeAt(il); //reflect the change to the current list
278    }
279  } //end of empty list check
280 
281  //Make sure that there is an item selected
282  if(ui->tree_install_apps->topLevelItemCount() > 0 ){
283    if( ui->tree_install_apps->selectedItems().isEmpty() ){
284      ui->tree_install_apps->setCurrentItem( ui->tree_install_apps->topLevelItem(0) );
285    }
286    //Now re-size the columns to the minimum required width
287    for(int i=0; i<3; i++){
288      ui->tree_install_apps->resizeColumnToContents(i);
289    } 
290  }
291  slotUpdateSelectedPBI();; //Update the info boxes
292  slotDisplayStats();
293  slotCheckSelectedItems();
294  //If the browser app page is currently visible for this app
295  if( (ui->stacked_browser->currentWidget() == ui->page_app) && ui->page_app->isVisible() ){
296    slotGoToApp(cApp);
297  }
298}
299
300void MainUI::slotCheckSelectedItems(){
301  bool chkd = false;
302  for(int i=0; i<ui->tree_install_apps->topLevelItemCount(); i++){
303    if(ui->tree_install_apps->topLevelItem(i)->checkState(0) == Qt::Checked){
304      chkd = true; break;
305    }
306  }
307  ui->tool_install_performaction->setEnabled(chkd);
308}
309
310void MainUI::slotPBIStatusUpdate(QString pbiID){
311  //This will do a full update of a particlar PBI entry
312  //    and just update/check the icons for all the other PBI's
313  for(int i=0; i<ui->tree_install_apps->topLevelItemCount(); i++){
314    QString itemID = ui->tree_install_apps->topLevelItem(i)->whatsThis(0);
315    if(itemID == pbiID){
316      QString stat = PBI->PBIInfo(pbiID,QStringList()<<"status").join("");
317      ui->tree_install_apps->topLevelItem(i)->setText(2,stat);
318      // See if we need to update the download progress bar
319      QString appID = ui->tree_install_apps->currentItem()->whatsThis(0);
320      if ( appID == pbiID ) {
321        slotUpdateSelectedPBI();
322        //If the details page is currently visible, update it too
323        if(ui->stackedWidget->currentWidget() == ui->page_install_details){
324          updateInstallDetails(appID);
325        }
326      }
327    }else{
328      //Just check/update the icon if necessary
329      if(ui->tree_install_apps->topLevelItem(i)->icon(0).isNull()){
330         ui->tree_install_apps->topLevelItem(i)->setIcon(0, QIcon( PBI->PBIInfo(itemID, QStringList() << "icon").join("") ));
331      }
332    }
333  }
334  //If the browser app page is current for this app
335  QString metaID = PBI->pbiToAppID(pbiID);
336  if( (ui->stacked_browser->currentWidget() == ui->page_app) && (cApp == metaID) && ui->page_app->isVisible() ){
337    slotUpdateAppDownloadButton();
338  }
339}
340
341void MainUI::on_tool_install_details_clicked(){
342  //Get the current item
343  QString appID;
344  if(ui->tree_install_apps->topLevelItemCount() > 0){
345    appID = ui->tree_install_apps->currentItem()->whatsThis(0);
346  }
347  if(appID.isEmpty()){return;}
348  //Update the info on the details page
349  updateInstallDetails(appID);
350  //Now show the page
351  ui->stackedWidget->setCurrentWidget(ui->page_install_details);
352}
353
354void MainUI::on_tool_install_back_clicked(){
355  //List page should always be current based upon backend
356  ui->stackedWidget->setCurrentWidget(ui->page_install_list);
357}
358
359void MainUI::on_tool_install_gotobrowserpage_clicked(){
360  //When you want to open up the browser page for an application
361  QString appID = Extras::nameToID( ui->tree_install_apps->currentItem()->text(0) );
362  slotGoToApp(appID);
363}
364
365void MainUI::on_tool_install_toggleall_clicked(){
366  //Determine if the current item is checked or unchecked
367  bool checkall = (ui->tree_install_apps->currentItem()->checkState(0) == Qt::Unchecked);
368  for(int i=0; i<ui->tree_install_apps->topLevelItemCount(); i++){
369    if(checkall){ ui->tree_install_apps->topLevelItem(i)->setCheckState(0,Qt::Checked); }
370    else{ui->tree_install_apps->topLevelItem(i)->setCheckState(0,Qt::Unchecked); }
371  }
372  slotCheckSelectedItems();
373}
374
375void MainUI::on_tree_install_apps_itemSelectionChanged(){
376  //When an installed PBI is clicked on
377  slotUpdateSelectedPBI();
378  if(ui->stackedWidget->currentWidget() != ui->page_install_list){
379    ui->stackedWidget->setCurrentWidget(ui->page_install_list);
380  }
381  slotCheckSelectedItems();
382}
383
384void MainUI::on_tree_install_apps_itemDoubleClicked(QTreeWidgetItem *item){
385 //Make sure it is a valid/installed application
386 QString appID = item->whatsThis(0);
387  appID = PBI->isInstalled(appID);
388  if(appID.isEmpty()){ return; } //invalid item
389  //Update the info on the details page
390  updateInstallDetails(appID);
391  //Now show the page
392  ui->stackedWidget->setCurrentWidget(ui->page_install_details);
393}
394
395void MainUI::on_check_install_autoupdate_clicked(){
396  //Get the current item
397  QString appID;
398  if(ui->tree_install_apps->topLevelItemCount() > 0){
399    appID = ui->tree_install_apps->currentItem()->whatsThis(0);
400  }
401  if(appID.isEmpty()){return;}
402  //Now determine the current state of the checkbox
403  bool enabled = ui->check_install_autoupdate->isChecked();
404  //Now have the backend make the change
405  PBI->enableAutoUpdate(appID, enabled);
406  //Now ask if the user also wants to start updating it now
407  if(enabled && !PBI->upgradeAvailable(appID).isEmpty()){
408    if( QMessageBox::Yes == QMessageBox::question(this, tr("Start Update?"), tr("Do you wish to start updating this application right now?"), QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes) ){
409      PBI->upgradePBI(QStringList() << appID);
410    }
411  }
412  //Now force the info on the page to be updated in a moment (need time for database to update)
413  QTimer::singleShot(200, this, SLOT(on_tool_install_details_clicked()) );
414}
415
416void MainUI::on_tool_install_update_clicked(){
417  //Get the current item
418  QString appID;
419  if(ui->tree_install_apps->topLevelItemCount() > 0){
420    appID = ui->tree_install_apps->currentItem()->whatsThis(0);
421  }
422  if(appID.isEmpty()){return;}
423  PBI->upgradePBI(QStringList() << appID);
424}
425
426void MainUI::on_tool_install_remove_clicked(){
427  //Get the current item
428  QString appID;
429  if(ui->tree_install_apps->topLevelItemCount() > 0){
430    appID = ui->tree_install_apps->currentItem()->whatsThis(0);
431  }
432  if(appID.isEmpty()){return;}
433  //Verify removal
434  if( QMessageBox::Yes == QMessageBox::question(this,tr("Verify PBI Removal"), tr("Are you sure you wish to remove this application?")+"\n\n"+appID,QMessageBox::Yes | QMessageBox::Cancel,QMessageBox::Cancel) ){
435    PBI->removePBI(QStringList() << appID);
436  }
437}
438
439void MainUI::on_tool_install_cancel_clicked(){
440  //Get the current item
441  QString appID;
442  if(ui->tree_install_apps->topLevelItemCount() > 0){
443    appID = ui->tree_install_apps->currentItem()->whatsThis(0);
444  }
445  if(appID.isEmpty()){return;}
446  PBI->cancelActions(QStringList() << appID);
447 
448}
449
450void MainUI::on_tool_install_maintainer_clicked(){
451  //Get the current item
452  QString appID;
453  if(ui->tree_install_apps->topLevelItemCount() > 0){
454    appID = ui->tree_install_apps->currentItem()->whatsThis(0);
455  }
456  if(appID.isEmpty()){return;}
457  //Get the maintainer email
458  QString email = PBI->PBIInfo(appID, QStringList() << "maintainer").join("");
459  if(email.isEmpty()){ return; }
460  qDebug() << "Launching email to:" << email;
461  //Get the command from the action
462  QString cmd = "mailto:"+email;
463  QStringList info = PBI->PBIInfo(appID, QStringList() << "name" << "date" << "version" << "arch" << "fbsdversion" );
464  //Add a sample subject
465  cmd.append("?subject="+info[0]+" port question");
466  //Add the info to the body of the email
467  cmd.append("&body=");
468  cmd.append("-----------\nPBI Information:\nName: "+info[0] + "\nDate Created: "+info[1] +"\nVersion: "+info[2] +"\nArchitecture: "+info[3] +"\nFreeBSD Version: "+info[4] );
469  //Startup the command externally
470  QProcess::execute("xdg-open \""+cmd+"\"");
471}
472
473// === SELECTED PBI ACTIONS ===
474void MainUI::slotActionAddDesktop(){
475  QStringList items = getCheckedItems();
476  PBI->addDesktopIcons(items,FALSE); //only for current user
477}
478
479void MainUI::slotActionRemoveDesktop(){
480  QStringList items = getCheckedItems();
481  PBI->rmDesktopIcons(items,FALSE);  //Only for current user
482}
483
484void MainUI::slotActionAddPath(){
485  QStringList items = getCheckedItems();
486  PBI->addPaths(items,FALSE);  //Only for current user 
487}
488
489void MainUI::slotActionRemovePath(){
490  QStringList items = getCheckedItems();
491  PBI->rmPaths(items,FALSE);  //Only for current user
492}
493
494void MainUI::slotActionAddPathAll(){
495  QStringList items = getCheckedItems();
496  PBI->addPaths(items,TRUE);  //For all users (root permissions required)
497}
498
499void MainUI::slotActionAddMenu(){
500  QStringList items = getCheckedItems();
501  PBI->addMenuIcons(items,FALSE);  //Only for current user
502}
503
504void MainUI::slotActionRemoveMenu(){
505  QStringList items = getCheckedItems();
506  PBI->rmMenuIcons(items,FALSE);  //Only for current user       
507}
508
509void MainUI::slotActionAddMenuAll(){
510  QStringList items = getCheckedItems();
511  PBI->addMenuIcons(items,TRUE);  //For all users (root permissions required)   
512}
513
514void MainUI::slotActionAddMime(){
515  QStringList items = getCheckedItems();
516  PBI->addMimeTypes(items,FALSE);  //Only for current user     
517}
518
519void MainUI::slotActionRemoveMime(){
520  QStringList items = getCheckedItems();
521  PBI->rmMimeTypes(items,FALSE);  //Only for current user       
522}
523
524void MainUI::slotActionAddMimeAll(){
525    QStringList items = getCheckedItems();
526  PBI->addMimeTypes(items,TRUE);  //For all users (root permissions required)   
527}
528
529void MainUI::slotActionUpdate(){
530  QStringList checkedID = getCheckedItems();
531  if(!checkedID.isEmpty()){
532    PBI->upgradePBI(checkedID); 
533  }
534}
535
536void MainUI::slotActionRemove(){
537  QStringList checkedID = getCheckedItems();
538  if(!checkedID.isEmpty()){
539    //Verify that the user really wants to remove these apps
540    if( QMessageBox::Yes == QMessageBox::question(this,tr("Verify PBI Removal"), tr("Are you sure you wish to remove these applications?")+"\n\n"+checkedID.join("\n"),QMessageBox::Yes | QMessageBox::Cancel,QMessageBox::Cancel) ){
541      PBI->removePBI(checkedID);
542    }
543  }
544}
545
546void MainUI::slotActionCancel(){
547  QStringList checkedID = getCheckedItems();
548  if(!checkedID.isEmpty()){
549    PBI->cancelActions(checkedID); 
550  }
551}
552
553void MainUI::slotStartApp(QAction* act){
554  qDebug() << "Starting external application:" << act->text();
555  //Get the command from the action
556  QString desktopfile = act->whatsThis();
557  QString cmd = "xdg-open "+desktopfile;
558  //Startup the command externally
559  QProcess::execute(cmd);
560}
561
562void MainUI::slotUpdateSelectedPBI(){
563  //Get the currently selected app
564  QString appID;
565  if(ui->tree_install_apps->topLevelItemCount() > 0){
566    appID = ui->tree_install_apps->currentItem()->whatsThis(0);
567  }
568  //See if this one is actually installed
569  appID = PBI->isInstalled(appID);
570  if(appID.isEmpty()){
571    ui->tool_install_details->setEnabled(false);
572  }else{
573    ui->tool_install_details->setEnabled(true);   
574  }
575   
576}
577
578void MainUI::updateInstallDetails(QString appID){
579  //Get the information to update the details page
580  //Get the PBI info for that item
581    QStringList vals; 
582    vals << "name" << "icon" << "author" << "website" << "version" << "license" << "description" << "maintainer" << "date" << "arch";
583    QStringList bools;
584    bools << "autoupdate" << "hasdesktopicons" << "hasmenuicons" << "requiresroot";
585    vals = PBI->PBIInfo(appID,vals);
586    bools = PBI->PBIInfo(appID,bools);
587    //Make sure the info lists are not empty
588    if(vals.isEmpty() || bools.isEmpty()){
589      ui->tool_install_details->setEnabled(false);
590      return; 
591    }
592    //Load a default icon if none found
593    if(vals[1].isEmpty()){ vals[1] = defaultIcon; }
594    //Now set the info on the UI
595    bool desktopSC = (bools[1] == "true"); // XDG desktop entries available
596    bool menuSC= (bools[2] == "true");   // XDG menu entries available
597    bool autoupdate = (bools[0] == "true"); //auto-update enabled
598    bool rootonly = (bools[3] == "true"); //requires root
599    //Create the shortcuts string
600    QString shortcuts;
601      if(desktopSC && menuSC){ shortcuts = tr("Desktop/Menu"); }
602      else if(desktopSC){ shortcuts = tr("Desktop"); }
603      else if(menuSC){ shortcuts = tr("Menu"); }
604      else{ shortcuts = tr("None"); }
605    //Now display that info on the UI
606    ui->label_install_app->setText(vals[0]);
607    ui->label_install_icon->setPixmap( QPixmap(vals[1]).scaled(64,64, Qt::KeepAspectRatio, Qt::SmoothTransformation) );
608    if(vals[3].isEmpty()){ 
609      ui->label_install_author->setText(vals[2]); 
610      ui->label_install_author->setToolTip("");
611    }else{ 
612      ui->label_install_author->setText("<a href="+vals[3]+">"+vals[2]+"</a>"); 
613      ui->label_install_author->setToolTip(vals[3]); //show website URL as tooltip
614    }
615    ui->label_install_version->setText(vals[4]);
616    ui->label_install_license->setText(vals[5]);
617    ui->text_install_description->setPlainText(vals[6]);
618    ui->tool_install_maintainer->setVisible( vals[7].contains("@") );
619    ui->label_install_date->setText(vals[8]);
620    ui->label_install_arch->setText(vals[9]);
621    ui->label_install_shortcuts->setText(shortcuts);
622    ui->check_install_autoupdate->setChecked(autoupdate);
623 
624    //Adjust the quick action buttons as necessary
625    if( PBI->isWorking(appID) ){
626      //Actions pending/working only show cancel button
627      ui->tool_install_cancel->setVisible(TRUE);
628      ui->tool_install_remove->setVisible(FALSE);
629      ui->tool_install_update->setVisible(FALSE);
630      ui->tool_install_startApp->setVisible(FALSE);
631    }else{
632      //Nothing pending
633      ui->tool_install_cancel->setVisible(FALSE);
634      if( !PBI->isInstalled(appID).isEmpty() ){ 
635        //Remove Button
636        ui->tool_install_remove->setVisible(TRUE);
637        if(rootonly){ ui->tool_install_remove->setIcon(QIcon(":icons/remove-root.png")); }
638        else{ ui->tool_install_remove->setIcon(QIcon(":icons/remove.png")); }
639        //Update
640        if(PBI->upgradeAvailable(appID).isEmpty()){ ui->tool_install_update->setVisible(FALSE); }
641        else{
642          ui->tool_install_update->setVisible(TRUE); 
643          if(rootonly){ ui->tool_install_update->setIcon(QIcon(":icons/app_upgrade_small-root.png")); }
644          else{ ui->tool_install_update->setIcon(QIcon(":icons/app_upgrade_small.png")); }
645        }
646        //Start Application binaries
647        QStringList bins = PBI->pbiBinList(appID);
648        appBinMenu->clear();
649        for(int i=0; i<bins.length(); i++){
650          QAction *act = new QAction(this);
651            act->setText(bins[i].section("::::",0,0)); //set name
652            act->setWhatsThis(bins[i].section("::::",1,10)); //set command string
653          appBinMenu->addAction(act);
654        }
655        if(appBinMenu->isEmpty()){ ui->tool_install_startApp->setVisible(FALSE); }
656        else{ ui->tool_install_startApp->setVisible(TRUE); }
657      }else{ 
658        ui->tool_install_remove->setVisible(FALSE); 
659        ui->tool_install_update->setVisible(FALSE); 
660        ui->tool_install_startApp->setVisible(FALSE);
661      }   
662    }
663
664  //Update the current status indicators
665  QString stat = PBI->currentAppStatus(appID,true); //get the raw status
666  QString statF = PBI->currentAppStatus(appID, false); //get the non-raw status
667  if( stat.isEmpty() && statF.isEmpty() ){
668    //Not currently running - hide the display indicators
669    ui->group_install_appStat->setVisible(false);
670  }else if(stat.startsWith("DLSTAT::")){
671    //Currently downloading - show download status indicators
672    QString percent = stat.section("::",1,1);
673    QString total = stat.section("::",2,2);
674    QString speed = stat.section("::",3,3);
675    ui->group_install_appStat->setVisible(TRUE);
676      ui->progress_install_DL->setVisible(TRUE);
677    if(total == "??"){ ui->label_install_status->setText( tr("Downloading file:") ); }
678    else{ ui->label_install_status->setText( QString(tr("Downloading %1 file:")).arg(total) ); }
679    if(percent == "??"){
680      ui->progress_install_DL->setMinimum(0); ui->progress_install_DL->setMaximum(0);
681    }else{
682      ui->progress_install_DL->setMinimum(0); ui->progress_install_DL->setMaximum(1000);
683      ui->progress_install_DL->setValue( int(percent.toFloat()*10) );
684    }
685    if(speed == "??"){ ui->label_install_DL->setVisible(FALSE); }
686    else{
687      ui->label_install_DL->setVisible(TRUE);
688      ui->label_install_DL->setText(speed);
689    }
690  }else{
691    //Currently installing/removing/updating - show last message from process
692    if(!statF.isEmpty()){ ui->label_install_status->setText(statF); }
693    else{ ui->label_install_status->setText(stat); }
694    ui->group_install_appStat->setVisible(TRUE);
695      ui->progress_install_DL->setVisible(FALSE);
696      ui->label_install_DL->setVisible(FALSE);
697  }
698}
699
700// ==========================
701// ====== BROWSER TAB =======
702// ==========================
703void MainUI::initializeBrowserTab(){
704  ui->tab_browse->setEnabled(FALSE);
705  //Always make sure that the browser starts off on the "home" page
706  ui->stacked_browser->setCurrentWidget(ui->page_home);
707  //With invisible shortcut buttons
708  ui->tool_browse_cat->setVisible(FALSE);
709  ui->tool_browse_app->setVisible(FALSE);
710  //Clear any items left over from the designer form
711  clearScrollArea(ui->scroll_br_home_newapps);
712  clearScrollArea(ui->scroll_br_home_cats);
713  //Search functionality
714  searchTimer = new QTimer();
715    searchTimer->setSingleShot(TRUE);
716    searchTimer->setInterval(300); // 0.3 sec wait before a search
717    connect(searchTimer,SIGNAL(timeout()),this,SLOT(slotGoToSearch()) );
718  connect(ui->tool_browse_search,SIGNAL(clicked()),this,SLOT(slotGoToSearch()) );
719  connect(ui->line_browse_searchbar,SIGNAL(returnPressed()),this,SLOT(slotGoToSearch()) );
720}
721
722// === SLOTS ===
723void MainUI::slotDisableBrowser(bool shownotification){
724  if(shownotification){ qDebug() << "No Repo Available: De-activating the Browser"; }
725  ui->tabWidget->setCurrentWidget(ui->tab_installed);
726  ui->tab_browse->setEnabled(FALSE);
727  slotDisplayStats();
728}
729
730void MainUI::slotEnableBrowser(){
731  qDebug() << "Repo Ready: - generating browser home page";
732  //Now create the browser home page
733  slotUpdateBrowserHome();
734  //And allow the user to go there
735  ui->tab_browse->setEnabled(TRUE);
736  slotDisplayStats();
737}
738
739void MainUI::slotUpdateBrowserHome(){
740  //Load the Categories
741  QStringList cats = PBI->browserCategories();
742  clearScrollArea(ui->scroll_br_home_cats);
743  QVBoxLayout *catlayout = new QVBoxLayout;
744  QStringList info; info << "name" << "description" << "icon";
745  cats.sort(); //sort them alphabetically
746  for(int i=0; i<cats.length(); i++){
747    QStringList data = PBI->CatInfo(cats[i],info);
748    if(!data.isEmpty()){
749      LargeItemWidget *item = new LargeItemWidget(cats[i],data[0],data[1],data[2]);
750      connect(item,SIGNAL(appClicked(QString)),this,SLOT(slotGoToCategory(QString)) );
751      catlayout->addWidget(item);
752    }
753  }
754  catlayout->addStretch(); //add a spacer to the end
755  ui->scroll_br_home_cats->widget()->setLayout(catlayout);
756  //Load the newest applications
757  clearScrollArea(ui->scroll_br_home_newapps);
758  QHBoxLayout *newapplayout = new QHBoxLayout;
759  QStringList newapps = PBI->getRecentApps();
760  for(int i=0; i<newapps.length(); i++){
761    QStringList appdata = PBI->AppInfo(newapps[i],QStringList() << "name" << "icon" << "latestversion");
762    if(!appdata.isEmpty()){
763      SmallItemWidget *item = new SmallItemWidget(newapps[i],appdata[0],appdata[1],appdata[2]);
764      connect(item,SIGNAL(appClicked(QString)),this,SLOT(slotGoToApp(QString)) );
765      newapplayout->addWidget(item);
766    }
767  }
768  newapplayout->addStretch(); //add a spacer to the end
769  newapplayout->setContentsMargins(0,0,0,0);
770  newapplayout->setSpacing(0);
771  ui->scroll_br_home_newapps->widget()->setLayout(newapplayout);
772  //Make sure that the newapps scrollarea is the proper fit vertically (no vertical scrolling)
773  ui->scroll_br_home_newapps->setMinimumHeight(ui->scroll_br_home_newapps->widget()->minimumSizeHint().height()+ui->scroll_br_home_newapps->horizontalScrollBar()->height());
774 
775  //Make sure the new apps area is invisible if no items available
776  if(newapps.isEmpty()){ ui->group_br_home_newapps->setVisible(FALSE); }
777  else{ ui->group_br_home_newapps->setVisible(TRUE); }
778  //make sure the home page is visible in the browser (slotGoToHome without changing tabs)
779  ui->stacked_browser->setCurrentWidget(ui->page_home); 
780  //Make sure the shortcut buttons are disabled
781  ui->tool_browse_cat->setVisible(FALSE);
782  ui->tool_browse_app->setVisible(FALSE); 
783 
784}
785
786void MainUI::slotGoToHome(){
787  ui->tabWidget->setCurrentWidget(ui->tab_browse);
788  ui->stacked_browser->setCurrentWidget(ui->page_home); 
789  //Make sure the shortcut buttons are disabled
790  ui->tool_browse_cat->setVisible(FALSE);
791  ui->tool_browse_app->setVisible(FALSE);
792}
793
794void MainUI::slotGoToCategory(QString cat){
795  qDebug() << "Show Category:" << cat;
796  //Get the apps in this category
797  QStringList apps = PBI->browserApps(cat);
798  if(apps.isEmpty()){
799    qDebug() << "Invalid category:" << cat;
800    return;
801  }
802  clearScrollArea(ui->scroll_br_cat_apps);
803  apps.sort();
804  QVBoxLayout *applayout = new QVBoxLayout;
805  QStringList info; info << "name" << "shortdescription" << "icon";
806  for(int i=0; i<apps.length(); i++){
807    QStringList data = PBI->AppInfo(apps[i],info);
808    if(!data.isEmpty()){
809      //Trim the description if necessary
810      if(data[1].size()>100){ data[1] = data[1].left(100).append("..."); }
811      LargeItemWidget *item = new LargeItemWidget(apps[i],data[0],data[1],data[2]);
812      connect(item,SIGNAL(appClicked(QString)),this,SLOT(slotGoToApp(QString)) );
813      applayout->addWidget(item); 
814    }
815  }
816  applayout->addStretch();
817  ui->scroll_br_cat_apps->widget()->setLayout(applayout);
818  //Now enable/disable the shortcut buttons
819  ui->tool_browse_app->setVisible(FALSE);
820  ui->tool_browse_cat->setVisible(TRUE);
821    QStringList catinfo = PBI->CatInfo(cat,QStringList() << "name" << "icon");
822    ui->tool_browse_cat->setText(catinfo[0]);
823    if(catinfo[1].isEmpty()){ catinfo[1] = defaultIcon; }
824    ui->tool_browse_cat->setIcon(QIcon(catinfo[1]));
825  ui->tabWidget->setCurrentWidget(ui->tab_browse);
826  ui->stacked_browser->setCurrentWidget(ui->page_cat);
827  //Now save that this category is currently displayed
828  cCat = cat;
829}
830
831void MainUI::slotGoToApp(QString appID){
832  qDebug() << "Show App:" << appID;
833  //Get the general application info
834  QStringList data; 
835  data << "name" << "icon" << "author" << "website" << "license" << "type" << "description" \
836       << "category" << "requiresroot" << "latestversion" << "latestarch" <<"latestsize" \
837       << "backupversion" << "backuparch" << "backupsize";
838  data = PBI->AppInfo(appID,data);
839  if(data.isEmpty()){
840    qDebug() << "Invalid App:" << appID;
841    return;
842  }
843  cApp = appID; //save this for later
844  //Start the search for similar apps
845  PBI->searchSimilar = appID;
846  ui->group_bapp_similar->setVisible(FALSE);
847  QTimer::singleShot(0,PBI,SLOT(startSimilarSearch()));
848  //Now Check icon
849  if(data[1].isEmpty()){ data[1] = defaultIcon; }
850  //Now fill the UI with the data
851  ui->label_bapp_name->setText(data[0]);
852  ui->label_bapp_icon->setPixmap(QPixmap(data[1]));
853  if(data[3].isEmpty()){ ui->label_bapp_authorweb->setText(data[2]); }
854  else{ ui->label_bapp_authorweb->setText("<a href="+data[3]+">"+data[2]+"</a>"); }
855  ui->label_bapp_authorweb->setToolTip(data[3]);
856  ui->label_bapp_license->setText(data[4]);
857  ui->label_bapp_type->setText(data[5]);
858  ui->text_bapp_description->setText(data[6]);
859  //Now determine the appropriate version info
860  QString pbiID = PBI->isInstalled(appID); //get pbiID
861  QString cVer;
862  if(!pbiID.isEmpty()){ cVer = PBI->PBIInfo(pbiID,QStringList("version")).join(""); }
863  bool useLatest=FALSE;
864  bool nobackup = data[12].isEmpty();
865  if(cVer.isEmpty()){ useLatest=TRUE; } //not currently installed
866  else if(cVer != data[9]){ useLatest=TRUE;} //not the latest version
867  //Now put the proper version info on the UI
868  if(useLatest || nobackup){
869    ui->label_bapp_version->setText(data[9]);
870    ui->label_bapp_arch->setText(data[10]);
871    if(data[11].isEmpty()){ ui->label_bapp_size->setText(tr("Unknown")); }
872    else{ ui->label_bapp_size->setText( Extras::sizeKToDisplay(data[11]) ); }
873  }else{
874    ui->label_bapp_version->setText(data[12]);
875    ui->label_bapp_arch->setText(data[13]);
876    if(data[14].isEmpty()){ ui->label_bapp_size->setText(tr("Unknown")); }
877    else{ ui->label_bapp_size->setText( Extras::sizeKToDisplay(data[14]) ); }
878  }
879  //Now update the download button appropriately
880  slotUpdateAppDownloadButton();
881
882  //Now enable/disable the shortcut buttons
883  ui->tool_browse_app->setVisible(TRUE);
884    ui->tool_browse_app->setText(data[0]);
885    ui->tool_browse_app->setIcon(QIcon(data[1]));
886  QStringList catinfo = PBI->CatInfo(Extras::nameToID(data[7]),QStringList() << "name" << "icon");
887  if(!catinfo.isEmpty()){
888    ui->tool_browse_cat->setVisible(TRUE);
889    ui->tool_browse_cat->setText(catinfo[0]);
890    if(catinfo[1].isEmpty()){ catinfo[1] = defaultIcon; }
891    ui->tool_browse_cat->setIcon(QIcon(catinfo[1]));
892  }
893  ui->tabWidget->setCurrentWidget(ui->tab_browse);
894  ui->stacked_browser->setCurrentWidget(ui->page_app);
895       
896}
897
898void MainUI::slotUpdateAppDownloadButton(){
899  QString ico;
900  QString working = PBI->currentAppStatus(cApp);
901  QStringList info = PBI->AppInfo(cApp, QStringList() << "latestversion" << "backupversion" << "requiresroot");
902  QString pbiID = PBI->isInstalled(cApp);
903  if(!working.isEmpty()){ //app currently pending or actually doing something
904    ui->tool_bapp_download->setText(working);
905    ui->tool_bapp_download->setIcon(QIcon(":icons/working.png"));
906    ui->tool_bapp_download->setEnabled(FALSE);
907  }else if( pbiID.isEmpty() ){ //new installation
908    ui->tool_bapp_download->setText(tr("Install Now!"));
909    ico = ":icons/app_download.png";
910    ui->tool_bapp_download->setEnabled(TRUE);
911  }else if( !PBI->upgradeAvailable(pbiID).isEmpty() ){ //Update available
912    ui->tool_bapp_download->setText(tr("Update"));
913    ico = ":icons/app_upgrade.png";
914    ui->tool_bapp_download->setEnabled(TRUE);
915  }else if(!info[1].isEmpty()){  //Downgrade available
916    ui->tool_bapp_download->setText(tr("Downgrade"));
917    ico = ":icons/app_downgrade.png";
918    ui->tool_bapp_download->setEnabled(TRUE);
919  }else{ //already installed (no downgrade available)
920    ui->tool_bapp_download->setText(tr("Installed"));
921    ui->tool_bapp_download->setIcon(QIcon(":icons/dialog-ok.png"));
922    ui->tool_bapp_download->setEnabled(FALSE);
923  }
924  //Now set the icon appropriately if it requires root permissions
925  if(!ico.isEmpty()){
926    if(info[2]=="true"){ //requires root permissions to install
927      ico.replace(".png","-root.png");
928    }
929    ui->tool_bapp_download->setIcon(QIcon(ico));
930  }
931  ui->tool_bapp_download->setWhatsThis(cApp); //set for slot
932}
933
934void MainUI::slotGoToSearch(){
935  searchTimer->stop(); //just in case "return" was pressed to start the search
936  QString search = ui->line_browse_searchbar->text();
937  if(search.isEmpty()){ return; }
938  PBI->searchTerm = search;
939  QTimer::singleShot(1,PBI,SLOT(startAppSearch()));
940  ui->label_bsearch_info->setText( tr("Searching the application database. Please Wait....") );
941    ui->label_bsearch_info->setVisible(TRUE);
942    ui->group_bsearch_best->setVisible(FALSE);
943    ui->group_bsearch_other->setVisible(FALSE);
944 
945}
946       
947void MainUI::slotShowSimilarApps(QStringList apps){
948  qDebug() << " - Similar applications:" << apps;
949  if(apps.isEmpty()){ ui->group_bapp_similar->setVisible(FALSE); }
950  else{
951    clearScrollArea(ui->scroll_bapp_similar);
952    QHBoxLayout *layout = new QHBoxLayout;
953    for(int i=0; i<apps.length(); i++){
954      QStringList appdata = PBI->AppInfo(apps[i],QStringList() << "name" << "icon");
955      if(!appdata.isEmpty()){
956        SmallItemWidget *item = new SmallItemWidget(apps[i],appdata[0],appdata[1],"");
957        connect(item,SIGNAL(appClicked(QString)),this,SLOT(slotGoToApp(QString)) );
958        layout->addWidget(item);
959      }
960    }
961    layout->addStretch(); //add a spacer to the end
962    layout->setContentsMargins(1,1,1,1);
963    ui->scroll_bapp_similar->widget()->setLayout(layout);
964    //Make sure that the similar scrollarea is the proper fit vertically (no vertical scrolling)
965    ui->scroll_bapp_similar->setMinimumHeight(ui->scroll_bapp_similar->widget()->minimumSizeHint().height()+ui->scroll_bapp_similar->horizontalScrollBar()->height());
966    //Now make the group visible as appropriate
967    ui->group_bapp_similar->setVisible(TRUE);
968    if(ui->group_bapp_similar->isChecked()){ ui->scroll_bapp_similar->setVisible(TRUE); }
969    else{ ui->scroll_bapp_similar->setVisible(FALSE); }
970    //Now make sure the app page has the proper layout dimensions
971    ui->page_app->updateGeometry();
972  }
973}
974
975void MainUI::slotShowSearchResults(QStringList best, QStringList rest){
976  //Now display the search results
977  if(best.isEmpty()){
978    ui->label_bsearch_info->setText( QString(tr("No Search Results Found for the term: %1")).arg(ui->line_browse_searchbar->text()) );
979    ui->label_bsearch_info->setVisible(TRUE);
980    ui->group_bsearch_best->setVisible(FALSE);
981    ui->group_bsearch_other->setVisible(FALSE);
982  }else{
983    ui->label_bsearch_info->setVisible(FALSE);
984    //Now fill the "best" section
985    clearScrollArea(ui->scroll_bsearch_best);
986    QVBoxLayout *layout = new QVBoxLayout;
987    QStringList info; info << "name" << "shortdescription" << "icon";
988    for(int i=0; i<best.length(); i++){
989      QStringList data = PBI->AppInfo(best[i],info);
990      if(!data.isEmpty()){
991        //Trim the description if necessary
992        if(data[1].size()>100){ data[1] = data[1].left(100).append("..."); }
993        LargeItemWidget *item = new LargeItemWidget(best[i],data[0],data[1],data[2]);
994        connect(item,SIGNAL(appClicked(QString)),this,SLOT(slotGoToApp(QString)) );
995        layout->addWidget(item); 
996      }
997    }
998    layout->addStretch();
999    ui->scroll_bsearch_best->widget()->setLayout(layout);
1000    ui->group_bsearch_best->setVisible(TRUE);
1001   
1002    //Now fill the other results
1003    if(rest.isEmpty()){ ui->group_bsearch_other->setVisible(FALSE); }
1004    else{
1005      ui->group_bsearch_other->setVisible(TRUE);
1006      clearScrollArea(ui->scroll_bsearch_other);
1007      QVBoxLayout *layout2 = new QVBoxLayout;
1008      for(int i=0; i<rest.length(); i++){
1009        QStringList data = PBI->AppInfo(rest[i],info);
1010        if(!data.isEmpty()){
1011          //Trim the description if necessary
1012          if(data[1].size()>100){ data[1] = data[1].left(100).append("..."); }
1013          LargeItemWidget *item = new LargeItemWidget(rest[i],data[0],data[1],data[2]);
1014          connect(item,SIGNAL(appClicked(QString)),this,SLOT(slotGoToApp(QString)) );
1015          layout2->addWidget(item); 
1016        }
1017      }
1018      layout2->addStretch();
1019      ui->scroll_bsearch_other->widget()->setLayout(layout2);
1020    }
1021  }
1022       
1023  //need to make sure the search bar still has keyboard focus (just in case)
1024  ui->tabWidget->setCurrentWidget(ui->tab_browse);
1025  ui->stacked_browser->setCurrentWidget(ui->page_search);
1026 
1027}
1028
1029void MainUI::on_tabWidget_currentChanged(){
1030  if(ui->tabWidget->currentWidget() == ui->tab_browse){
1031    //Refresh the app page if that is the one currently showing
1032    if(ui->stacked_browser->currentWidget() == ui->page_app){ on_tool_browse_app_clicked(); }     
1033  }else{
1034    //Always return to the installed list
1035    ui->stackedWidget->setCurrentWidget(ui->page_install_list);
1036  }
1037}
1038
1039void MainUI::on_tool_browse_home_clicked(){
1040  slotGoToHome();
1041}
1042
1043void MainUI::on_tool_browse_cat_clicked(){
1044  QString cat = Extras::nameToID(ui->tool_browse_cat->text());
1045  if(cCat == cat){ //already loaded - just show it (prevents resetting scroll positions)
1046    ui->stacked_browser->setCurrentWidget(ui->page_cat);
1047  }else{ //load and show the category
1048    slotGoToCategory(cat);
1049  }
1050}
1051
1052void MainUI::on_tool_browse_app_clicked(){
1053  QString appID = Extras::nameToID(ui->tool_browse_app->text());
1054  slotGoToApp(appID);
1055}
1056
1057void MainUI::on_line_browse_searchbar_textChanged(){
1058  //Connect this to a singleshot timer, so the search functionality is only
1059  //  run once after a short wait rather than every time a new character is typed
1060 
1061  //Live search only after 3 characters have been typed
1062  if(ui->line_browse_searchbar->text().length() > 2){
1063    searchTimer->start();
1064  }else{
1065    searchTimer->stop();         
1066  }
1067}
1068
1069void MainUI::on_tool_bapp_download_clicked(){
1070  QString appID = ui->tool_bapp_download->whatsThis();
1071  //Verify the app installation
1072  if( QMessageBox::Yes != QMessageBox::question(this,tr("Verify Installation"), tr("Are you sure you want to install this application?")+"\n\n"+appID,QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes)){
1073    return;
1074  }
1075  PBI->installApp(QStringList() << appID);
1076  ui->tool_bapp_download->setEnabled(FALSE); //make sure it cannot be clicked more than once before page refresh
1077  //Now show the Installed tab
1078  //ui->tabWidget->setCurrentWidget(ui->tab_installed);
1079}
1080
1081void MainUI::on_group_br_home_newapps_toggled(bool show){
1082  ui->scroll_br_home_newapps->setVisible(show);
1083}
1084
1085void MainUI::on_group_bapp_similar_toggled(bool show){
1086  ui->scroll_bapp_similar->setVisible(show);
1087}
1088
1089// ================================
1090// ==========  OTHER ==============
1091// ================================
1092void MainUI::clearScrollArea(QScrollArea* area){
1093  QWidget *wgt = area->takeWidget();
1094  delete wgt; //delete the widget and all children
1095  area->setWidget( new QWidget() ); //create a new widget in the scroll area
1096  area->widget()->setContentsMargins(0,0,0,0);
1097}
1098
1099void MainUI::slotDisplayError(QString title,QString message,QStringList log){
1100  QMessageBox *dlg = new QMessageBox(this);
1101    dlg->setWindowTitle(title);
1102    dlg->setText(message);
1103    dlg->setDetailedText(log.join("\n"));
1104  dlg->exec();
1105}
1106
1107void MainUI::slotDisplayStats(){
1108  int avail = PBI->numAvailable;
1109  int installed = PBI->numInstalled;
1110  QString text;
1111  if(avail == -1){
1112    text = QString(tr("Installed: %1")).arg(QString::number(installed)); 
1113  }else{
1114    text = QString(tr("Installed: %1")+"\t"+tr("Available: %2")).arg(QString::number(installed), QString::number(avail)); 
1115  }
1116  //Get the number of installed/available applications and display it
1117  statusLabel->setText(text);   
1118}
Note: See TracBrowser for help on using the repository browser.