Changeset fdad871


Ignore:
Timestamp:
02/26/14 09:24:56 (8 months ago)
Author:
Ken Moore <ken@…>
Branches:
master, releng/10.0.1, releng/10.0.2, releng/10.0.3
Children:
c4ff3c1
Parents:
8538c35
Message:

Add a custom context menu to the AppCafe? installed PBI list that is dynamically created for that particular application.

Location:
src-qt4/pc-softwaremanager
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • src-qt4/pc-softwaremanager/mainUI.cpp

    refbe467 rfdad871  
    145145// ========================= 
    146146void MainUI::initializeInstalledTab(){ 
     147         
    147148  //Setup the action menu for installed applications 
    148149  actionMenu = new QMenu(); 
     
    190191  ui->tool_install_startApp->setMenu(appBinMenu); 
    191192    connect(appBinMenu, SIGNAL(triggered(QAction*)), this, SLOT(slotStartApp(QAction*)) ); 
     193  //Initialize the context menu 
     194  contextActionMenu = new QMenu(this); 
     195    connect(contextActionMenu, SIGNAL(aboutToHide()), this, SLOT(contextMenuFinished()) ); 
    192196  //Now setup the action button 
    193197  ui->tool_install_performaction->setMenu(actionMenu); 
     
    195199  //Now setup any defaults for the installed tab 
    196200  ui->tree_install_apps->setIconSize(QSize(22,22)); 
     201  ui->tree_install_apps->setContextMenuPolicy(Qt::CustomContextMenu); 
    197202  connect(ui->tree_install_apps, SIGNAL(itemClicked(QTreeWidgetItem*, int)), this, SLOT(slotCheckSelectedItems()) ); 
     203  connect(ui->tree_install_apps, SIGNAL(customContextMenuRequested(const QPoint &)), this, SLOT( slotInstalledAppRightClicked(const QPoint &)) ); 
    198204  slotRefreshInstallTab(); 
    199205} 
     
    223229  //Return the pbiID's of all the active items 
    224230  QStringList output; 
    225   //See if we are on the single-app details page - then get the current app only 
     231  //See if we are on the single-app details page or custom context menu- then get the current app only 
    226232  if(ui->stackedWidget->currentWidget() == ui->page_install_details){ 
    227233      output << cDetails;   
     234           
     235  //Check for whether this is the context menu on the main widget 
     236  }else if(!cDetails.isEmpty()){ 
     237     output << cDetails; 
     238     cDetails.clear(); 
    228239           
    229240  //If on the main Installed page, look for checked items only 
     
    323334  } 
    324335  ui->tool_install_performaction->setEnabled(chkd); 
     336  if(ui->stackedWidget->currentWidget() != ui->page_app){ 
     337    cDetails.clear(); //Make sure this is cleared if not on the details page 
     338  } 
    325339} 
    326340 
     
    486500  //Startup the command externally 
    487501  QProcess::execute("xdg-open \""+cmd+"\""); 
     502} 
     503 
     504void MainUI::slotInstalledAppRightClicked(const QPoint &pt){ 
     505  //Get the item under the mouse click 
     506  QString pbiID = ui->tree_install_apps->itemAt(pt)->whatsThis(0); 
     507  qDebug() << "Get context menu for:" << pbiID; 
     508  //Now Update the context menu appropriately 
     509  QStringList info = PBI->PBIInfo(pbiID, QStringList() << "hasdesktopicons" << "hasmenuicons" << "hasmimetypes"); 
     510  if(info.isEmpty()){ return; } //invalid application 
     511  bool pending = PBI->isWorking(pbiID); 
     512  contextActionMenu->clear(); 
     513  if(!PBI->upgradeAvailable(pbiID).isEmpty() &&  !pending){ 
     514    //Upgrade is only available if actions not pending 
     515    contextActionMenu->addAction( QIcon(":icons/view-refresh.png"), tr("Update"), this, SLOT(slotActionUpdate()) ); 
     516    contextActionMenu->addSeparator(); 
     517  } 
     518  if(info[0]=="true"){ 
     519    QMenu *dmenu = contextActionMenu->addMenu( QIcon(":icons/xdg_desktop.png"), tr("Desktop Icons")); 
     520      dmenu->addAction( QIcon(":icons/add.png"),tr("Add"),this,SLOT(slotActionAddDesktop()) ); 
     521      dmenu->addAction( QIcon(":icons/remove.png"),tr("Remove"),this,SLOT(slotActionRemoveDesktop()) ); 
     522  } 
     523  if(info[1]=="true"){ 
     524    QMenu *mmenu = contextActionMenu->addMenu( QIcon(":icons/xdg_menu.png"), tr("Menu Icons")); 
     525      mmenu->addAction( QIcon(":icons/add.png"),tr("Add"),this,SLOT(slotActionAddMenu()) ); 
     526      mmenu->addAction( QIcon(":icons/remove.png"),tr("Remove"),this,SLOT(slotActionRemoveMenu()) );   
     527      mmenu->addAction( QIcon(":icons/add-root.png"),tr("Add (All Users)"),this,SLOT(slotActionAddMenuAll()) ); 
     528  } 
     529  //Paths are always available 
     530    QMenu *pmenu = contextActionMenu->addMenu( QIcon(":icons/xdg_paths.png"), tr("Path Links")); 
     531      pmenu->addAction( QIcon(":icons/add.png"),tr("Add"),this,SLOT(slotActionAddPath()) ); 
     532      pmenu->addAction( QIcon(":icons/remove.png"),tr("Remove"),this,SLOT(slotActionRemovePath()) );   
     533      pmenu->addAction( QIcon(":icons/add-root.png"),tr("Add (All Users)"),this,SLOT(slotActionAddPathAll()) ); 
     534  if(info[2]=="true"){ 
     535    QMenu *fmenu = contextActionMenu->addMenu( QIcon(":icons/xdg_mime.png"), tr("File Associations")); 
     536      fmenu->addAction( QIcon(":icons/add.png"),tr("Add"),this,SLOT(slotActionAddMime()) ); 
     537      fmenu->addAction( QIcon(":icons/remove.png"),tr("Remove"),this,SLOT(slotActionRemoveMime()) );   
     538      fmenu->addAction( QIcon(":icons/add-root.png"),tr("Add (All Users)"),this,SLOT(slotActionAddMimeAll()) ); 
     539  } 
     540  if(!pending){ 
     541    //Remove option is only available if not currently pending actions 
     542    contextActionMenu->addSeparator(); 
     543    contextActionMenu->addAction( QIcon(":icons/remove.png"), tr("Uninstall"), this, SLOT(slotActionRemove()) ); 
     544  } 
     545  if(pending){ 
     546    //Cancel option is only available if actions are currently pending     
     547    contextActionMenu->addSeparator(); 
     548    contextActionMenu->addAction( QIcon(":icons/dialog-cancel.png"), tr("Cancel Actions"), this, SLOT(slotActionCancel()) ); 
     549  } 
     550  //Now show the menu 
     551  cDetails = pbiID; //save this so we know which app is currently being modified 
     552  contextActionMenu->popup(ui->tree_install_apps->mapToGlobal(pt)); 
     553} 
     554 
     555void MainUI::contextMenuFinished(){ 
     556  QTimer::singleShot(500, this, SLOT(slotCheckSelectedItems()) );        
    488557} 
    489558 
  • src-qt4/pc-softwaremanager/mainUI.h

    r32be23f rfdad871  
    7171  void on_tool_install_cancel_clicked(); 
    7272  void on_tool_install_maintainer_clicked(); 
     73  void slotInstalledAppRightClicked(const QPoint &); 
     74  void contextMenuFinished(); 
    7375  void slotActionAddDesktop(); 
    7476  void slotActionRemoveDesktop(); 
     
    116118  PBIBackend *PBI; 
    117119  //INSTALLED TAB 
    118   QMenu *actionMenu, *appBinMenu, *shortcutMenu, *sDeskMenu, *sMenuMenu, *sMimeMenu; 
     120  QMenu *actionMenu, *appBinMenu, *shortcutMenu, *sDeskMenu, *sMenuMenu, *sMimeMenu, *contextActionMenu; 
    119121  QString cDetails; 
    120122  void initializeInstalledTab(); 
  • src-qt4/pc-softwaremanager/mainUI.ui

    refbe467 rfdad871  
    5050        </property> 
    5151        <property name="topMargin"> 
    52          <number>0</number> 
     52         <number>4</number> 
    5353        </property> 
    5454        <property name="rightMargin"> 
     
    5656        </property> 
    5757        <property name="bottomMargin"> 
    58          <number>0</number> 
     58         <number>4</number> 
    5959        </property> 
    6060        <item> 
Note: See TracChangeset for help on using the changeset viewer.