source: src-qt4/pc-mounttray/fsDialog.cpp @ be298e4

9.1-release9.2-releasereleng/10.0releng/10.0.1releng/10.0.2releng/10.0.3
Last change on this file since be298e4 was be298e4, checked in by Ken Moore <ken@…>, 17 months ago

Clean up the new mount-tray disk place dialog, it now looks nice and highlights the devices that are almost full.

  • Property mode set to 100644
File size: 2.6 KB
Line 
1#include "fsDialog.h"
2
3FSDialog::FSDialog() : QDialog(){
4  generateUI();
5}
6
7FSDialog::~FSDialog(){
8}
9
10void FSDialog::generateUI(){
11  //Auto-generate the UI
12  QVBoxLayout *vlayout = new QVBoxLayout();
13  //Filesystem display widget
14  QTreeWidget *tree = new QTreeWidget(this);
15    tree->setIndentation(0);
16    //tree->setSizePolicy( QSizePolicy::MinimumExpanding, QSizePolicy::Preferred );
17    //setup the column headers
18    tree->setColumnCount(4);
19    QStringList header;
20    header << tr("Mount Point") << tr("Filesystem") << tr("Used/Total") << tr("Percent %");
21    tree->setHeaderLabels(header);
22   
23    //Auto fill the scroll area
24    QStringList fsList = FSWatcher::getFSmountpoints();
25    //Format: mountpoint::filesystem::totalspace(K)::usedspace(K)::percentUsed
26    for(int i=0; i<fsList.length(); i++){
27      //Get the data for this item
28      QString name = fsList[i].section("::",0,0);
29      QString filesystem = fsList[i].section("::",1,1);
30      int totalK = fsList[i].section("::",2,2).toInt();
31      int usedK = fsList[i].section("::",3,3).toInt();
32      int percent = fsList[i].section("::",4,4).toInt();
33      //Create item for the data
34      QStringList text; //column text
35      text << name << filesystem.toUpper() << FSWatcher::intToDisplay(usedK)+"/"+FSWatcher::intToDisplay(totalK) << QString::number(percent)+"%";
36      QTreeWidgetItem *tmp = new QTreeWidgetItem(text);
37     
38      //set the item background based upon urgency
39      if(percent < 75){} //do nothing
40      else if(percent < 90){ // yellow
41        QBrush color(QColor(237,233,12));
42        tmp->setBackground(0,color); tmp->setBackground(1,color);
43        tmp->setBackground(2,color); tmp->setBackground(3,color);
44      }
45      else{  //red
46        QBrush color(QColor(237,12,53));
47        tmp->setBackground(0,color); tmp->setBackground(1,color);
48        tmp->setBackground(2,color); tmp->setBackground(3,color);
49      }   
50      //Now add the item to the widget
51      tree->addTopLevelItem(tmp);
52    }
53   
54  vlayout->addWidget(tree);
55  //Make sure the widget is the smallest size possible
56  tree->resizeColumnToContents(0); tree->resizeColumnToContents(1);
57  tree->resizeColumnToContents(2); tree->resizeColumnToContents(3);
58  //Now add the close button to the bottom
59  QHBoxLayout *hb = new QHBoxLayout();
60  hb->addStretch();
61  QPushButton *closeButton = new QPushButton("Close");
62  hb->addWidget(closeButton);
63  hb->addStretch();
64  vlayout->addLayout(hb);
65  connect(closeButton,SIGNAL(clicked()),this,SLOT(closeDialog()));
66  //Now set the layout for the dialog
67  this->setLayout(vlayout);
68  //Now resize the dialog to fit the widget appropriately
69  this->adjustSize();
70}
71
72void FSDialog::closeDialog(){
73  this->close();
74}
Note: See TracBrowser for help on using the repository browser.