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

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

Get the mountTray saving/loading it's settings properly, and integrate those settings with the new Settings dlialog. You can now turn the disk space watcher off/on and set the refresh times/flags within the settings dialog.

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