Code: Alles auswählen
#ifndef FS_H
#define FS_H
#include <QtGui>
#include <iostream>
#include "FS.h"
#include "processParser.h"
#include "txt_parse.h"
class FS : public QWidget
{
Q_OBJECT
private:
//config widgets:
QComboBox *mountpoint;
QComboBox *filesystem;
QComboBox *sec_part;
QComboBox *check_consistence;
//string for config changes
QString deviceChanges;
//layout
QHBoxLayout *FSConfig_Layout;
void createFSConfig_Layout();
QTableWidget *fstab;
//configuration
QStringList str_hard_devices;
QStringList str_mountpoint;
QStringList str_filesystem;
QStringList str_mountoptions;
QStringList str_security;
QStringList str_consistence;
void readDevices(); //"/etc/fstab" + "fdisk -l"
//connections
void connector();
private slots:
void saveSelection(QString);
public:
FS(QWidget *parent = 0);
signals:
};
#endif
Code: Alles auswählen
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include "FS.h"
FS::FS(QWidget *parent) : QWidget(parent)
{
QVBoxLayout *mainLayout = new QVBoxLayout(this);
//set up str_hard_devices!
readDevices();
//main config layout
FS::createFSConfig_Layout();
mainLayout->addLayout(FSConfig_Layout);
//connect config widgets...
FS::connector();
}
void FS::createFSConfig_Layout()
{
FSConfig_Layout = new QHBoxLayout;
if(str_hard_devices.size() > 0)
fstab = new QTableWidget(str_hard_devices.size(), 5); //spalten neu setzen... wenn funktionen fertig..
else fstab = new QTableWidget(1, 5);
//set up labels...
fstab->setHorizontalHeaderLabels(QStringList() << "Mountpoint:" << "Filesystem"
<< "Mount options:" << "Security:" << "Consistence");
fstab->setVerticalHeaderLabels(str_hard_devices);
//set up config widget...
for(int i = 0; i < str_hard_devices.size(); i++)
{
mountpoint = new QComboBox;
mountpoint->setEditable(true);
fstab->setCellWidget(i, 0, mountpoint);
for(int j = 0; j < str_mountpoint.size(); j++)
{
if(str_mountpoint.at(j).section("\t", 0, 0) == str_hard_devices.at(i) )
mountpoint->insertItem(0, str_mountpoint.at(j).section("\t", 1, 1) );
}
filesystem = new QComboBox;
fstab->setCellWidget(i, 1, filesystem);
//...here we have to fill the mount options
sec_part = new QComboBox;
fstab->setCellWidget(i, 3, sec_part);
check_consistence = new QComboBox;
fstab->setCellWidget(i, 4, check_consistence);
}
FSConfig_Layout->addWidget(fstab);
}
void FS::connector()
{
QObject::connect(mountpoint, SIGNAL(currentIndexChanged (QString) ), this, SLOT(saveSelection(QString) ) );
}
void FS::readDevices()
{
//fstab to compare it with...
QStringList fstab;
fstab = readConf("fstab", "/etc/");
for(int i = 0; i < fstab.size(); i++)
{
if(fstab.at(i).section(" ", 0, 0).contains("/dev/hd") )
{
str_mountpoint.append(fstab.at(i).section(" ", 0, 0)+ "\t" + fstab.at(i).section(" ", 1, 1) );
str_filesystem.append(fstab.at(i).section(" ", 0, 0)+ "\t" + fstab.at(i).section(" ", 2, 2) );
str_mountoptions.append(fstab.at(i).section(" ", 0, 0)+ "\t" + fstab.at(i).section(" ", 3, 3) );
str_security.append(fstab.at(i).section(" ", 0, 0)+ "\t" + fstab.at(i).section(" ", 4, 4) );
str_consistence.append(fstab.at(i).section(" ", 0, 0)+ "\t" + fstab.at(i).section(" ", 5, 5) );
}
}
//...this!
QStringList getDev;
getDev = getPrcOutP("fdisk", QStringList() << "-l");
for(int i = 0; i < getDev.size(); i++)
{
QString temp = getDev.at(i);
if(temp.section(" ", 0, 0).contains("/dev/hd") && !temp.contains("Erweiterte") ) //have to get fixed for other languages!!!
str_hard_devices.append(temp.section(" ", 0, 0) );
}
}
//slots (private)
void FS::saveSelection(QString str)
{
if(!deviceChanges.isEmpty() )
deviceChanges.append("\t" + str);
else deviceChanges = str;
}
hier erstmal der abschnitt:
Code: Alles auswählen
void FS::createFSConfig_Layout()
{
FSConfig_Layout = new QHBoxLayout;
if(str_hard_devices.size() > 0)
fstab = new QTableWidget(str_hard_devices.size(), 5); //spalten neu setzen... wenn funktionen fertig..
else fstab = new QTableWidget(1, 5);
//set up labels...
fstab->setHorizontalHeaderLabels(QStringList() << "Mountpoint:" << "Filesystem"
<< "Mount options:" << "Security:" << "Consistence");
fstab->setVerticalHeaderLabels(str_hard_devices);
//set up config widget...
for(int i = 0; i < str_hard_devices.size(); i++)
{
mountpoint = new QComboBox;
mountpoint->setEditable(true);
fstab->setCellWidget(i, 0, mountpoint);
for(int j = 0; j < str_mountpoint.size(); j++)
{
if(str_mountpoint.at(j).section("\t", 0, 0) == str_hard_devices.at(i) )
mountpoint->insertItem(0, str_mountpoint.at(j).section("\t", 1, 1) );
}
filesystem = new QComboBox;
fstab->setCellWidget(i, 1, filesystem);
//...here we have to fill the mount options
sec_part = new QComboBox;
fstab->setCellWidget(i, 3, sec_part);
check_consistence = new QComboBox;
fstab->setCellWidget(i, 4, check_consistence);
}
FSConfig_Layout->addWidget(fstab);
}(filesystem = new QComboBox;) nun bin ich mir nicht ganz sicher wie ich dass mit den connects zu dem widgets lösen sollte
bisher wird zwar zum programmstart in jedes mountpoint combo ein anderer text (der in der datei steht) geladen, aber ich ahbe gar keine ahnung wie sich dass dann bei veränderungen und dem connecten verhält, da ich ja kein neues widget erstellt habe, sondern immer nur neuen speicher allokierte.
allerdings fällt mir sonst nicht ein wie man eine variabel große tabelle machen könnte...
fällt euch eine andere löung ein, oder wie würdet ihr das machen? ich habe schon keine vaage idee, wollte aber erstmal anregungen holen? oder andere methoden...
postet doch einfachmal ein paar sachen, wie ihr meine connector-methode machen würdet?! um für jede zeile der tabele ein spezifisches signal zu erhalten.
denn jede zeile der tabelle soll den inhalt all ihrer widgets zu einem QString zusammenfügen. diese zeilen werden dann zu einer qstringlist verbunden und dann wieder zurück geschrieben, in die datei.
ich hoffe, ich belästige damit niemanden.... aber ich versuche besser zu werden...