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

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

Add the ability for the AppCafe? to install random PBI files on the system through a menu option, and update the Installed tab interface a bit to make it more uniform between the two pages. Still have a couple things to do to finish it up, but it is perfectly functional.

  • Property mode set to 100644
File size: 45.6 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}
295
296void MainUI::slotCheckSelectedItems(){
297  bool chkd = false;
298  for(int i=0; i<ui->tree_install_apps->topLevelItemCount(); i++){
299    if(ui->tree_install_apps->topLevelItem(i)->checkState(0) == Qt::Checked){
300      chkd = true; break;
301    }
302  }
303  ui->tool_install_performaction->setEnabled(chkd);
304}
305
306void MainUI::slotPBIStatusUpdate(QString pbiID){
307  //This will do a full update of a particlar PBI entry
308  //    and just update/check the icons for all the other PBI's
309  for(int i=0; i<ui->tree_install_apps->topLevelItemCount(); i++){
310    QString itemID = ui->tree_install_apps->topLevelItem(i)->whatsThis(0);
311    if(itemID == pbiID){
312      QString stat = PBI->PBIInfo(pbiID,QStringList()<<"status").join("");
313      ui->tree_install_apps->topLevelItem(i)->setText(2,stat);
314      // See if we need to update the download progress bar
315      QString appID = ui->tree_install_apps->currentItem()->whatsThis(0);
316      if ( appID == pbiID ) {
317        slotUpdateSelectedPBI();
318        //If the details page is currently visible, update it too
319        if(ui->stackedWidget->currentWidget() == ui->page_install_details){
320          updateInstallDetails(appID);
321        }
322      }
323    }else{
324      //Just check/update the icon if necessary
325      if(ui->tree_install_apps->topLevelItem(i)->icon(0).isNull()){
326         ui->tree_install_apps->topLevelItem(i)->setIcon(0, QIcon( PBI->PBIInfo(itemID, QStringList() << "icon").join("") ));
327      }
328    }
329  }
330}
331
332void MainUI::on_tool_install_details_clicked(){
333  //Get the current item
334  QString appID;
335  if(ui->tree_install_apps->topLevelItemCount() > 0){
336    appID = ui->tree_install_apps->currentItem()->whatsThis(0);
337  }
338  if(appID.isEmpty()){return;}
339  //Update the info on the details page
340  updateInstallDetails(appID);
341  //Now show the page
342  ui->stackedWidget->setCurrentWidget(ui->page_install_details);
343}
344
345void MainUI::on_tool_install_back_clicked(){
346  //List page should always be current based upon backend
347  ui->stackedWidget->setCurrentWidget(ui->page_install_list);
348}
349
350void MainUI::on_tool_install_gotobrowserpage_clicked(){
351  //When you want to open up the browser page for an application
352  QString appID = Extras::nameToID( ui->tree_install_apps->currentItem()->text(0) );
353  slotGoToApp(appID);
354}
355
356void MainUI::on_tool_install_toggleall_clicked(){
357  //Determine if the current item is checked or unchecked
358  bool checkall = (ui->tree_install_apps->currentItem()->checkState(0) == Qt::Unchecked);
359  for(int i=0; i<ui->tree_install_apps->topLevelItemCount(); i++){
360    if(checkall){ ui->tree_install_apps->topLevelItem(i)->setCheckState(0,Qt::Checked); }
361    else{ui->tree_install_apps->topLevelItem(i)->setCheckState(0,Qt::Unchecked); }
362  }
363  slotCheckSelectedItems();
364}
365
366void MainUI::on_tree_install_apps_itemSelectionChanged(){
367  //When an installed PBI is clicked on
368  slotUpdateSelectedPBI();
369  if(ui->stackedWidget->currentWidget() != ui->page_install_list){
370    ui->stackedWidget->setCurrentWidget(ui->page_install_list);
371  }
372  slotCheckSelectedItems();
373}
374
375void MainUI::on_tree_install_apps_itemDoubleClicked(QTreeWidgetItem *item){
376 //Make sure it is a valid/installed application
377 QString appID = item->whatsThis(0);
378  appID = PBI->isInstalled(appID);
379  if(appID.isEmpty()){ return; } //invalid item
380  //Update the info on the details page
381  updateInstallDetails(appID);
382  //Now show the page
383  ui->stackedWidget->setCurrentWidget(ui->page_install_details);
384}
385
386void MainUI::on_check_install_autoupdate_clicked(){
387  //Get the current item
388  QString appID;
389  if(ui->tree_install_apps->topLevelItemCount() > 0){
390    appID = ui->tree_install_apps->currentItem()->whatsThis(0);
391  }
392  if(appID.isEmpty()){return;}
393  //Now determine the current state of the checkbox
394  bool enabled = ui->check_install_autoupdate->isChecked();
395  //Now have the backend make the change
396  PBI->enableAutoUpdate(appID, enabled);
397  //Now ask if the user also wants to start updating it now
398  if(enabled && !PBI->upgradeAvailable(appID).isEmpty()){
399    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) ){
400      PBI->upgradePBI(QStringList() << appID);
401    }
402  }
403  //Now force the info on the page to be updated in a moment (need time for database to update)
404  QTimer::singleShot(200, this, SLOT(on_tool_install_details_clicked()) );
405}
406
407void MainUI::on_tool_install_update_clicked(){
408  //Get the current item
409  QString appID;
410  if(ui->tree_install_apps->topLevelItemCount() > 0){
411    appID = ui->tree_install_apps->currentItem()->whatsThis(0);
412  }
413  if(appID.isEmpty()){return;}
414  PBI->upgradePBI(QStringList() << appID);
415}
416
417void MainUI::on_tool_install_remove_clicked(){
418  //Get the current item
419  QString appID;
420  if(ui->tree_install_apps->topLevelItemCount() > 0){
421    appID = ui->tree_install_apps->currentItem()->whatsThis(0);
422  }
423  if(appID.isEmpty()){return;}
424  //Verify removal
425  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) ){
426    PBI->removePBI(QStringList() << appID);
427  }
428}
429
430void MainUI::on_tool_install_cancel_clicked(){
431  //Get the current item
432  QString appID;
433  if(ui->tree_install_apps->topLevelItemCount() > 0){
434    appID = ui->tree_install_apps->currentItem()->whatsThis(0);
435  }
436  if(appID.isEmpty()){return;}
437  PBI->cancelActions(QStringList() << appID);
438 
439}
440
441void MainUI::on_tool_install_maintainer_clicked(){
442  //Get the current item
443  QString appID;
444  if(ui->tree_install_apps->topLevelItemCount() > 0){
445    appID = ui->tree_install_apps->currentItem()->whatsThis(0);
446  }
447  if(appID.isEmpty()){return;}
448  //Get the maintainer email
449  QString email = PBI->PBIInfo(appID, QStringList() << "maintainer").join("");
450  if(email.isEmpty()){ return; }
451  qDebug() << "Launching email to:" << email;
452  //Get the command from the action
453  QString cmd = "mailto:"+email;
454  QStringList info = PBI->PBIInfo(appID, QStringList() << "name" << "date" << "version" << "arch" << "fbsdversion" );
455  //Add a sample subject
456  cmd.append("?subject="+info[0]+" port question");
457  //Add the info to the body of the email
458  cmd.append("&body=");
459  cmd.append("-----------\nPBI Information:\nName: "+info[0] + "\nDate Created: "+info[1] +"\nVersion: "+info[2] +"\nArchitecture: "+info[3] +"\nFreeBSD Version: "+info[4] );
460  //Startup the command externally
461  QProcess::execute("xdg-open \""+cmd+"\"");
462}
463
464// === SELECTED PBI ACTIONS ===
465void MainUI::slotActionAddDesktop(){
466  QStringList items = getCheckedItems();
467  PBI->addDesktopIcons(items,FALSE); //only for current user
468}
469
470void MainUI::slotActionRemoveDesktop(){
471  QStringList items = getCheckedItems();
472  PBI->rmDesktopIcons(items,FALSE);  //Only for current user
473}
474
475void MainUI::slotActionAddPath(){
476  QStringList items = getCheckedItems();
477  PBI->addPaths(items,FALSE);  //Only for current user 
478}
479
480void MainUI::slotActionRemovePath(){
481  QStringList items = getCheckedItems();
482  PBI->rmPaths(items,FALSE);  //Only for current user
483}
484
485void MainUI::slotActionAddPathAll(){
486  QStringList items = getCheckedItems();
487  PBI->addPaths(items,TRUE);  //For all users (root permissions required)
488}
489
490void MainUI::slotActionAddMenu(){
491  QStringList items = getCheckedItems();
492  PBI->addMenuIcons(items,FALSE);  //Only for current user
493}
494
495void MainUI::slotActionRemoveMenu(){
496  QStringList items = getCheckedItems();
497  PBI->rmMenuIcons(items,FALSE);  //Only for current user       
498}
499
500void MainUI::slotActionAddMenuAll(){
501  QStringList items = getCheckedItems();
502  PBI->addMenuIcons(items,TRUE);  //For all users (root permissions required)   
503}
504
505void MainUI::slotActionAddMime(){
506  QStringList items = getCheckedItems();
507  PBI->addMimeTypes(items,FALSE);  //Only for current user     
508}
509
510void MainUI::slotActionRemoveMime(){
511  QStringList items = getCheckedItems();
512  PBI->rmMimeTypes(items,FALSE);  //Only for current user       
513}
514
515void MainUI::slotActionAddMimeAll(){
516    QStringList items = getCheckedItems();
517  PBI->addMimeTypes(items,TRUE);  //For all users (root permissions required)   
518}
519
520void MainUI::slotActionUpdate(){
521  QStringList checkedID = getCheckedItems();
522  if(!checkedID.isEmpty()){
523    PBI->upgradePBI(checkedID); 
524  }
525}
526
527void MainUI::slotActionRemove(){
528  QStringList checkedID = getCheckedItems();
529  if(!checkedID.isEmpty()){
530    //Verify that the user really wants to remove these apps
531    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) ){
532      PBI->removePBI(checkedID);
533    }
534  }
535}
536
537void MainUI::slotActionCancel(){
538  QStringList checkedID = getCheckedItems();
539  if(!checkedID.isEmpty()){
540    PBI->cancelActions(checkedID); 
541  }
542}
543
544void MainUI::slotStartApp(QAction* act){
545  qDebug() << "Starting external application:" << act->text();
546  //Get the command from the action
547  QString desktopfile = act->whatsThis();
548  QString cmd = "xdg-open "+desktopfile;
549  //Startup the command externally
550  QProcess::execute(cmd);
551}
552
553void MainUI::slotUpdateSelectedPBI(){
554  //Get the currently selected app
555  QString appID;
556  if(ui->tree_install_apps->topLevelItemCount() > 0){
557    appID = ui->tree_install_apps->currentItem()->whatsThis(0);
558  }
559  //See if this one is actually installed
560  appID = PBI->isInstalled(appID);
561  if(appID.isEmpty()){
562    ui->tool_install_details->setEnabled(false);
563  }else{
564    ui->tool_install_details->setEnabled(true);   
565  }
566   
567}
568
569void MainUI::updateInstallDetails(QString appID){
570  //Get the information to update the details page
571  //Get the PBI info for that item
572    QStringList vals; 
573    vals << "name" << "icon" << "author" << "website" << "version" << "license" << "description" << "maintainer" << "date" << "arch";
574    QStringList bools;
575    bools << "autoupdate" << "hasdesktopicons" << "hasmenuicons" << "requiresroot";
576    vals = PBI->PBIInfo(appID,vals);
577    bools = PBI->PBIInfo(appID,bools);
578    //Make sure the info lists are not empty
579    if(vals.isEmpty() || bools.isEmpty()){
580      ui->tool_install_details->setEnabled(false);
581      return; 
582    }
583    //Load a default icon if none found
584    if(vals[1].isEmpty()){ vals[1] = defaultIcon; }
585    //Now set the info on the UI
586    bool desktopSC = (bools[1] == "true"); // XDG desktop entries available
587    bool menuSC= (bools[2] == "true");   // XDG menu entries available
588    bool autoupdate = (bools[0] == "true"); //auto-update enabled
589    bool rootonly = (bools[3] == "true"); //requires root
590    //Create the shortcuts string
591    QString shortcuts;
592      if(desktopSC && menuSC){ shortcuts = tr("Desktop/Menu"); }
593      else if(desktopSC){ shortcuts = tr("Desktop"); }
594      else if(menuSC){ shortcuts = tr("Menu"); }
595      else{ shortcuts = tr("None"); }
596    //Now display that info on the UI
597    ui->label_install_app->setText(vals[0]);
598    ui->label_install_icon->setPixmap( QPixmap(vals[1]).scaled(64,64, Qt::KeepAspectRatio, Qt::SmoothTransformation) );
599    if(vals[3].isEmpty()){ 
600      ui->label_install_author->setText(vals[2]); 
601      ui->label_install_author->setToolTip("");
602    }else{ 
603      ui->label_install_author->setText("<a href="+vals[3]+">"+vals[2]+"</a>"); 
604      ui->label_install_author->setToolTip(vals[3]); //show website URL as tooltip
605    }
606    ui->label_install_version->setText(vals[4]);
607    ui->label_install_license->setText(vals[5]);
608    ui->text_install_description->setPlainText(vals[6]);
609    ui->tool_install_maintainer->setVisible( vals[7].contains("@") );
610    ui->label_install_date->setText(vals[8]);
611    ui->label_install_arch->setText(vals[9]);
612    ui->label_install_shortcuts->setText(shortcuts);
613    ui->check_install_autoupdate->setChecked(autoupdate);
614 
615    //Adjust the quick action buttons as necessary
616    if( PBI->isWorking(appID) ){
617      //Actions pending/working only show cancel button
618      ui->tool_install_cancel->setVisible(TRUE);
619      ui->tool_install_remove->setVisible(FALSE);
620      ui->tool_install_update->setVisible(FALSE);
621      ui->tool_install_startApp->setVisible(FALSE);
622    }else{
623      //Nothing pending
624      ui->tool_install_cancel->setVisible(FALSE);
625      if( !PBI->isInstalled(appID).isEmpty() ){ 
626        //Remove Button
627        ui->tool_install_remove->setVisible(TRUE);
628        if(rootonly){ ui->tool_install_remove->setIcon(QIcon(":icons/remove-root.png")); }
629        else{ ui->tool_install_remove->setIcon(QIcon(":icons/remove.png")); }
630        //Update
631        if(PBI->upgradeAvailable(appID).isEmpty()){ ui->tool_install_update->setVisible(FALSE); }
632        else{
633          ui->tool_install_update->setVisible(TRUE); 
634          if(rootonly){ ui->tool_install_update->setIcon(QIcon(":icons/app_upgrade_small-root.png")); }
635          else{ ui->tool_install_update->setIcon(QIcon(":icons/app_upgrade_small.png")); }
636        }
637        //Start Application binaries
638        QStringList bins = PBI->pbiBinList(appID);
639        appBinMenu->clear();
640        for(int i=0; i<bins.length(); i++){
641          QAction *act = new QAction(this);
642            act->setText(bins[i].section("::::",0,0)); //set name
643            act->setWhatsThis(bins[i].section("::::",1,10)); //set command string
644          appBinMenu->addAction(act);
645        }
646        if(appBinMenu->isEmpty()){ ui->tool_install_startApp->setVisible(FALSE); }
647        else{ ui->tool_install_startApp->setVisible(TRUE); }
648      }else{ 
649        ui->tool_install_remove->setVisible(FALSE); 
650        ui->tool_install_update->setVisible(FALSE); 
651        ui->tool_install_startApp->setVisible(FALSE);
652      }   
653    }
654
655  //Update the current status indicators
656  QString stat = PBI->currentAppStatus(appID,true); //get the raw status
657  QString statF = PBI->currentAppStatus(appID, false); //get the non-raw status
658  if( stat.isEmpty() && statF.isEmpty() ){
659    //Not currently running - hide the display indicators
660    ui->group_install_appStat->setVisible(false);
661  }else if(stat.startsWith("DLSTAT::")){
662    //Currently downloading - show download status indicators
663    QString percent = stat.section("::",1,1);
664    QString total = stat.section("::",2,2);
665    QString speed = stat.section("::",3,3);
666    ui->group_install_appStat->setVisible(TRUE);
667      ui->progress_install_DL->setVisible(TRUE);
668    if(total == "??"){ ui->label_install_status->setText( tr("Downloading file:") ); }
669    else{ ui->label_install_status->setText( QString(tr("Downloading %1 file:")).arg(total) ); }
670    if(percent == "??"){
671      ui->progress_install_DL->setMinimum(0); ui->progress_install_DL->setMaximum(0);
672    }else{
673      ui->progress_install_DL->setMinimum(0); ui->progress_install_DL->setMaximum(1000);
674      ui->progress_install_DL->setValue( int(percent.toFloat()*10) );
675    }
676    if(speed == "??"){ ui->label_install_DL->setVisible(FALSE); }
677    else{
678      ui->label_install_DL->setVisible(TRUE);
679      ui->label_install_DL->setText(speed);
680    }
681  }else{
682    //Currently installing/removing/updating - show last message from process
683    if(!statF.isEmpty()){ ui->label_install_status->setText(statF); }
684    else{ ui->label_install_status->setText(stat); }
685    ui->group_install_appStat->setVisible(TRUE);
686      ui->progress_install_DL->setVisible(FALSE);
687      ui->label_install_DL->setVisible(FALSE);
688  }
689}
690
691// ==========================
692// ====== BROWSER TAB =======
693// ==========================
694void MainUI::initializeBrowserTab(){
695  ui->tab_browse->setEnabled(FALSE);
696  //Always make sure that the browser starts off on the "home" page
697  ui->stacked_browser->setCurrentWidget(ui->page_home);
698  //With invisible shortcut buttons
699  ui->tool_browse_cat->setVisible(FALSE);
700  ui->tool_browse_app->setVisible(FALSE);
701  //Clear any items left over from the designer form
702  clearScrollArea(ui->scroll_br_home_newapps);
703  clearScrollArea(ui->scroll_br_home_cats);
704  //Search functionality
705  searchTimer = new QTimer();
706    searchTimer->setSingleShot(TRUE);
707    searchTimer->setInterval(300); // 0.3 sec wait before a search
708    connect(searchTimer,SIGNAL(timeout()),this,SLOT(slotGoToSearch()) );
709  connect(ui->tool_browse_search,SIGNAL(clicked()),this,SLOT(slotGoToSearch()) );
710  connect(ui->line_browse_searchbar,SIGNAL(returnPressed()),this,SLOT(slotGoToSearch()) );
711}
712
713// === SLOTS ===
714void MainUI::slotDisableBrowser(bool shownotification){
715  if(shownotification){ qDebug() << "No Repo Available: De-activating the Browser"; }
716  ui->tabWidget->setCurrentWidget(ui->tab_installed);
717  ui->tab_browse->setEnabled(FALSE);
718  slotDisplayStats();
719}
720
721void MainUI::slotEnableBrowser(){
722  qDebug() << "Repo Ready: - generating browser home page";
723  //Now create the browser home page
724  slotUpdateBrowserHome();
725  //And allow the user to go there
726  ui->tab_browse->setEnabled(TRUE);
727  slotDisplayStats();
728}
729
730void MainUI::slotUpdateBrowserHome(){
731  //Load the Categories
732  QStringList cats = PBI->browserCategories();
733  clearScrollArea(ui->scroll_br_home_cats);
734  QVBoxLayout *catlayout = new QVBoxLayout;
735  QStringList info; info << "name" << "description" << "icon";
736  cats.sort(); //sort them alphabetically
737  for(int i=0; i<cats.length(); i++){
738    QStringList data = PBI->CatInfo(cats[i],info);
739    if(!data.isEmpty()){
740      LargeItemWidget *item = new LargeItemWidget(cats[i],data[0],data[1],data[2]);
741      connect(item,SIGNAL(appClicked(QString)),this,SLOT(slotGoToCategory(QString)) );
742      catlayout->addWidget(item);
743    }
744  }
745  catlayout->addStretch(); //add a spacer to the end
746  ui->scroll_br_home_cats->widget()->setLayout(catlayout);
747  //Load the newest applications
748  clearScrollArea(ui->scroll_br_home_newapps);
749  QHBoxLayout *newapplayout = new QHBoxLayout;
750  QStringList newapps = PBI->getRecentApps();
751  for(int i=0; i<newapps.length(); i++){
752    QStringList appdata = PBI->AppInfo(newapps[i],QStringList() << "name" << "icon" << "latestversion");
753    if(!appdata.isEmpty()){
754      SmallItemWidget *item = new SmallItemWidget(newapps[i],appdata[0],appdata[1],appdata[2]);
755      connect(item,SIGNAL(appClicked(QString)),this,SLOT(slotGoToApp(QString)) );
756      newapplayout->addWidget(item);
757    }
758  }
759  newapplayout->addStretch(); //add a spacer to the end
760  newapplayout->setContentsMargins(0,0,0,0);
761  newapplayout->setSpacing(0);
762  ui->scroll_br_home_newapps->widget()->setLayout(newapplayout);
763  //Make sure that the newapps scrollarea is the proper fit vertically (no vertical scrolling)
764  ui->scroll_br_home_newapps->setMinimumHeight(ui->scroll_br_home_newapps->widget()->minimumSizeHint().height()+ui->scroll_br_home_newapps->horizontalScrollBar()->height());
765 
766  //Make sure the new apps area is invisible if no items available
767  if(newapps.isEmpty()){ ui->group_br_home_newapps->setVisible(FALSE); }
768  else{ ui->group_br_home_newapps->setVisible(TRUE); }
769  //make sure the home page is visible in the browser (slotGoToHome without changing tabs)
770  ui->stacked_browser->setCurrentWidget(ui->page_home); 
771  //Make sure the shortcut buttons are disabled
772  ui->tool_browse_cat->setVisible(FALSE);
773  ui->tool_browse_app->setVisible(FALSE); 
774 
775}
776
777void MainUI::slotGoToHome(){
778  ui->tabWidget->setCurrentWidget(ui->tab_browse);
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
785void MainUI::slotGoToCategory(QString cat){
786  qDebug() << "Show Category:" << cat;
787  //Get the apps in this category
788  QStringList apps = PBI->browserApps(cat);
789  if(apps.isEmpty()){
790    qDebug() << "Invalid category:" << cat;
791    return;
792  }
793  clearScrollArea(ui->scroll_br_cat_apps);
794  apps.sort();
795  QVBoxLayout *applayout = new QVBoxLayout;
796  QStringList info; info << "name" << "shortdescription" << "icon";
797  for(int i=0; i<apps.length(); i++){
798    QStringList data = PBI->AppInfo(apps[i],info);
799    if(!data.isEmpty()){
800      //Trim the description if necessary
801      if(data[1].size()>100){ data[1] = data[1].left(100).append("..."); }
802      LargeItemWidget *item = new LargeItemWidget(apps[i],data[0],data[1],data[2]);
803      connect(item,SIGNAL(appClicked(QString)),this,SLOT(slotGoToApp(QString)) );
804      applayout->addWidget(item); 
805    }
806  }
807  applayout->addStretch();
808  ui->scroll_br_cat_apps->widget()->setLayout(applayout);
809  //Now enable/disable the shortcut buttons
810  ui->tool_browse_app->setVisible(FALSE);
811  ui->tool_browse_cat->setVisible(TRUE);
812    QStringList catinfo = PBI->CatInfo(cat,QStringList() << "name" << "icon");
813    ui->tool_browse_cat->setText(catinfo[0]);
814    if(catinfo[1].isEmpty()){ catinfo[1] = defaultIcon; }
815    ui->tool_browse_cat->setIcon(QIcon(catinfo[1]));
816  ui->tabWidget->setCurrentWidget(ui->tab_browse);
817  ui->stacked_browser->setCurrentWidget(ui->page_cat);
818  //Now save that this category is currently displayed
819  cCat = cat;
820}
821
822void MainUI::slotGoToApp(QString appID){
823  qDebug() << "Show App:" << appID;
824  //Get the general application info
825  QStringList data; 
826  data << "name" << "icon" << "author" << "website" << "license" << "type" << "description" \
827       << "category" << "requiresroot" << "latestversion" << "latestarch" <<"latestsize" \
828       << "backupversion" << "backuparch" << "backupsize";
829  data = PBI->AppInfo(appID,data);
830  if(data.isEmpty()){
831    qDebug() << "Invalid App:" << appID;
832    return;
833  }
834  //Start the search for similar apps
835  PBI->searchSimilar = appID;
836  ui->group_bapp_similar->setVisible(FALSE);
837  QTimer::singleShot(0,PBI,SLOT(startSimilarSearch()));
838  //Now Check icon
839  if(data[1].isEmpty()){ data[1] = defaultIcon; }
840  //Now fill the UI with the data
841  ui->label_bapp_name->setText(data[0]);
842  ui->label_bapp_icon->setPixmap(QPixmap(data[1]));
843  if(data[3].isEmpty()){ ui->label_bapp_authorweb->setText(data[2]); }
844  else{ ui->label_bapp_authorweb->setText("<a href="+data[3]+">"+data[2]+"</a>"); }
845  ui->label_bapp_authorweb->setToolTip(data[3]);
846  ui->label_bapp_license->setText(data[4]);
847  ui->label_bapp_type->setText(data[5]);
848  ui->text_bapp_description->setText(data[6]);
849  //Now determine the appropriate version info
850  QString pbiID = PBI->isInstalled(appID); //get pbiID
851  QString cVer;
852  if(!pbiID.isEmpty()){ cVer = PBI->PBIInfo(pbiID,QStringList("version")).join(""); }
853  bool useLatest=FALSE;
854  bool nobackup = data[12].isEmpty();
855  if(cVer.isEmpty()){ useLatest=TRUE; } //not currently installed
856  else if(cVer != data[9]){ useLatest=TRUE;} //not the latest version
857  //Now put the proper version info on the UI
858  if(useLatest || nobackup){
859    ui->label_bapp_version->setText(data[9]);
860    ui->label_bapp_arch->setText(data[10]);
861    if(data[11].isEmpty()){ ui->label_bapp_size->setText(tr("Unknown")); }
862    else{ ui->label_bapp_size->setText( Extras::sizeKToDisplay(data[11]) ); }
863  }else{
864    ui->label_bapp_version->setText(data[12]);
865    ui->label_bapp_arch->setText(data[13]);
866    if(data[14].isEmpty()){ ui->label_bapp_size->setText(tr("Unknown")); }
867    else{ ui->label_bapp_size->setText( Extras::sizeKToDisplay(data[14]) ); }
868  }
869  //Now update the download button appropriately
870  QString ico;
871  QString working = PBI->currentAppStatus(appID);
872  if(!working.isEmpty()){ //app currently pending or actually doing something
873    ui->tool_bapp_download->setText(working);
874    ui->tool_bapp_download->setIcon(QIcon(":icons/working.png"));
875    ui->tool_bapp_download->setEnabled(FALSE);
876  }else if(useLatest && cVer.isEmpty()){ //new installation
877    ui->tool_bapp_download->setText(tr("Install Now!"));
878    ico = ":icons/app_download.png";
879    ui->tool_bapp_download->setEnabled(TRUE);
880  }else if(useLatest){ //Update available
881    ui->tool_bapp_download->setText(tr("Update"));
882    ico = ":icons/app_upgrade.png";
883    ui->tool_bapp_download->setEnabled(TRUE);
884  }else if(!nobackup){  //Downgrade available
885    ui->tool_bapp_download->setText(tr("Downgrade"));
886    ico = ":icons/app_downgrade.png";
887    ui->tool_bapp_download->setEnabled(TRUE);
888  }else{ //already installed (no downgrade available)
889    ui->tool_bapp_download->setText(tr("Installed"));
890    ui->tool_bapp_download->setIcon(QIcon(":icons/dialog-ok.png"));
891    ui->tool_bapp_download->setEnabled(FALSE);
892  }
893  //Now set the icon appropriately if it requires root permissions
894  if(!ico.isEmpty()){
895    if(data[8]=="true"){ //requires root permissions to install
896      ico.replace(".png","-root.png");
897    }
898    ui->tool_bapp_download->setIcon(QIcon(ico));
899  }
900  ui->tool_bapp_download->setWhatsThis(appID); //set for slot
901  //Now enable/disable the shortcut buttons
902  ui->tool_browse_app->setVisible(TRUE);
903    ui->tool_browse_app->setText(data[0]);
904    ui->tool_browse_app->setIcon(QIcon(data[1]));
905  QStringList catinfo = PBI->CatInfo(Extras::nameToID(data[7]),QStringList() << "name" << "icon");
906  if(!catinfo.isEmpty()){
907    ui->tool_browse_cat->setVisible(TRUE);
908    ui->tool_browse_cat->setText(catinfo[0]);
909    if(catinfo[1].isEmpty()){ catinfo[1] = defaultIcon; }
910    ui->tool_browse_cat->setIcon(QIcon(catinfo[1]));
911  }
912  ui->tabWidget->setCurrentWidget(ui->tab_browse);
913  ui->stacked_browser->setCurrentWidget(ui->page_app);
914       
915}
916
917void MainUI::slotGoToSearch(){
918  searchTimer->stop(); //just in case "return" was pressed to start the search
919  QString search = ui->line_browse_searchbar->text();
920  if(search.isEmpty()){ return; }
921  PBI->searchTerm = search;
922  QTimer::singleShot(1,PBI,SLOT(startAppSearch()));
923  ui->label_bsearch_info->setText( tr("Searching the application database. Please Wait....") );
924    ui->label_bsearch_info->setVisible(TRUE);
925    ui->group_bsearch_best->setVisible(FALSE);
926    ui->group_bsearch_other->setVisible(FALSE);
927 
928}
929       
930void MainUI::slotShowSimilarApps(QStringList apps){
931  qDebug() << " - Similar applications:" << apps;
932  if(apps.isEmpty()){ ui->group_bapp_similar->setVisible(FALSE); }
933  else{
934    clearScrollArea(ui->scroll_bapp_similar);
935    QHBoxLayout *layout = new QHBoxLayout;
936    for(int i=0; i<apps.length(); i++){
937      QStringList appdata = PBI->AppInfo(apps[i],QStringList() << "name" << "icon");
938      if(!appdata.isEmpty()){
939        SmallItemWidget *item = new SmallItemWidget(apps[i],appdata[0],appdata[1],"");
940        connect(item,SIGNAL(appClicked(QString)),this,SLOT(slotGoToApp(QString)) );
941        layout->addWidget(item);
942      }
943    }
944    layout->addStretch(); //add a spacer to the end
945    layout->setContentsMargins(1,1,1,1);
946    ui->scroll_bapp_similar->widget()->setLayout(layout);
947    //Make sure that the similar scrollarea is the proper fit vertically (no vertical scrolling)
948    ui->scroll_bapp_similar->setMinimumHeight(ui->scroll_bapp_similar->widget()->minimumSizeHint().height()+ui->scroll_bapp_similar->horizontalScrollBar()->height());
949    //Now make the group visible as appropriate
950    ui->group_bapp_similar->setVisible(TRUE);
951    if(ui->group_bapp_similar->isChecked()){ ui->scroll_bapp_similar->setVisible(TRUE); }
952    else{ ui->scroll_bapp_similar->setVisible(FALSE); }
953    //Now make sure the app page has the proper layout dimensions
954    ui->page_app->updateGeometry();
955  }
956}
957
958void MainUI::slotShowSearchResults(QStringList best, QStringList rest){
959  //Now display the search results
960  if(best.isEmpty()){
961    ui->label_bsearch_info->setText( QString(tr("No Search Results Found for the term: %1")).arg(ui->line_browse_searchbar->text()) );
962    ui->label_bsearch_info->setVisible(TRUE);
963    ui->group_bsearch_best->setVisible(FALSE);
964    ui->group_bsearch_other->setVisible(FALSE);
965  }else{
966    ui->label_bsearch_info->setVisible(FALSE);
967    //Now fill the "best" section
968    clearScrollArea(ui->scroll_bsearch_best);
969    QVBoxLayout *layout = new QVBoxLayout;
970    QStringList info; info << "name" << "shortdescription" << "icon";
971    for(int i=0; i<best.length(); i++){
972      QStringList data = PBI->AppInfo(best[i],info);
973      if(!data.isEmpty()){
974        //Trim the description if necessary
975        if(data[1].size()>100){ data[1] = data[1].left(100).append("..."); }
976        LargeItemWidget *item = new LargeItemWidget(best[i],data[0],data[1],data[2]);
977        connect(item,SIGNAL(appClicked(QString)),this,SLOT(slotGoToApp(QString)) );
978        layout->addWidget(item); 
979      }
980    }
981    layout->addStretch();
982    ui->scroll_bsearch_best->widget()->setLayout(layout);
983    ui->group_bsearch_best->setVisible(TRUE);
984   
985    //Now fill the other results
986    if(rest.isEmpty()){ ui->group_bsearch_other->setVisible(FALSE); }
987    else{
988      ui->group_bsearch_other->setVisible(TRUE);
989      clearScrollArea(ui->scroll_bsearch_other);
990      QVBoxLayout *layout2 = new QVBoxLayout;
991      for(int i=0; i<rest.length(); i++){
992        QStringList data = PBI->AppInfo(rest[i],info);
993        if(!data.isEmpty()){
994          //Trim the description if necessary
995          if(data[1].size()>100){ data[1] = data[1].left(100).append("..."); }
996          LargeItemWidget *item = new LargeItemWidget(rest[i],data[0],data[1],data[2]);
997          connect(item,SIGNAL(appClicked(QString)),this,SLOT(slotGoToApp(QString)) );
998          layout2->addWidget(item); 
999        }
1000      }
1001      layout2->addStretch();
1002      ui->scroll_bsearch_other->widget()->setLayout(layout2);
1003    }
1004  }
1005       
1006  //need to make sure the search bar still has keyboard focus (just in case)
1007  ui->tabWidget->setCurrentWidget(ui->tab_browse);
1008  ui->stacked_browser->setCurrentWidget(ui->page_search);
1009 
1010}
1011
1012void MainUI::on_tabWidget_currentChanged(){
1013  if(ui->tabWidget->currentWidget() == ui->tab_browse){
1014    //Refresh the app page if that is the one currently showing
1015    if(ui->stacked_browser->currentWidget() == ui->page_app){ on_tool_browse_app_clicked(); }     
1016  }else{
1017    //Always return to the installed list
1018    ui->stackedWidget->setCurrentWidget(ui->page_install_list);
1019  }
1020}
1021
1022void MainUI::on_tool_browse_home_clicked(){
1023  slotGoToHome();
1024}
1025
1026void MainUI::on_tool_browse_cat_clicked(){
1027  QString cat = Extras::nameToID(ui->tool_browse_cat->text());
1028  if(cCat == cat){ //already loaded - just show it (prevents resetting scroll positions)
1029    ui->stacked_browser->setCurrentWidget(ui->page_cat);
1030  }else{ //load and show the category
1031    slotGoToCategory(cat);
1032  }
1033}
1034
1035void MainUI::on_tool_browse_app_clicked(){
1036  QString appID = Extras::nameToID(ui->tool_browse_app->text());
1037  slotGoToApp(appID);
1038}
1039
1040void MainUI::on_line_browse_searchbar_textChanged(){
1041  //Connect this to a singleshot timer, so the search functionality is only
1042  //  run once after a short wait rather than every time a new character is typed
1043 
1044  //Live search only after 3 characters have been typed
1045  if(ui->line_browse_searchbar->text().length() > 2){
1046    searchTimer->start();
1047  }else{
1048    searchTimer->stop();         
1049  }
1050}
1051
1052void MainUI::on_tool_bapp_download_clicked(){
1053  QString appID = ui->tool_bapp_download->whatsThis();
1054  //Verify the app installation
1055  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)){
1056    return;
1057  }
1058  PBI->installApp(QStringList() << appID);
1059  ui->tool_bapp_download->setEnabled(FALSE); //make sure it cannot be clicked more than once before page refresh
1060  //Now show the Installed tab
1061  ui->tabWidget->setCurrentWidget(ui->tab_installed);
1062}
1063
1064void MainUI::on_group_br_home_newapps_toggled(bool show){
1065  ui->scroll_br_home_newapps->setVisible(show);
1066}
1067
1068void MainUI::on_group_bapp_similar_toggled(bool show){
1069  ui->scroll_bapp_similar->setVisible(show);
1070}
1071
1072// ================================
1073// ==========  OTHER ==============
1074// ================================
1075void MainUI::clearScrollArea(QScrollArea* area){
1076  QWidget *wgt = area->takeWidget();
1077  delete wgt; //delete the widget and all children
1078  area->setWidget( new QWidget() ); //create a new widget in the scroll area
1079  area->widget()->setContentsMargins(0,0,0,0);
1080}
1081
1082void MainUI::slotDisplayError(QString title,QString message,QStringList log){
1083  QMessageBox *dlg = new QMessageBox(this);
1084    dlg->setWindowTitle(title);
1085    dlg->setText(message);
1086    dlg->setDetailedText(log.join("\n"));
1087  dlg->exec();
1088}
1089
1090void MainUI::slotDisplayStats(){
1091  int avail = PBI->numAvailable;
1092  int installed = PBI->numInstalled;
1093  QString text;
1094  if(avail == -1){
1095    text = QString(tr("Installed: %1")).arg(QString::number(installed)); 
1096  }else{
1097    text = QString(tr("Installed: %1")+"\t"+tr("Available: %2")).arg(QString::number(installed), QString::number(avail)); 
1098  }
1099  //Get the number of installed/available applications and display it
1100  statusLabel->setText(text);   
1101}
Note: See TracBrowser for help on using the repository browser.