#include "winprefs.h" #include "mainwindow.h" #include #include winPrefs::winPrefs(MainWindow *world, QWidget* parent) : QDialog(parent) { setAttribute(Qt::WA_DeleteOnClose); pWorld = world; QSettings tmpSet("/sierra.conf", QSettings::IniFormat); setupUi(this); connect( this, SIGNAL(accepted()), this, SLOT(onAccepted()) ); // Load preferences fConnWorldName->setText(tmpSet.value("world/name", "Unnamed World").toString()); fConnHost->setText(tmpSet.value("world/host", "tapestries.fur.com").toString()); fConnPort->setText(tmpSet.value("world/port", "2069").toString()); fConnAutoConnect->setChecked( tmpSet.value("world/autoconnect", 0).toInt()); fConnAutoReconnect->setChecked( tmpSet.value("world/autoreconnect", 1).toInt() ); fConnClearInput->setChecked( tmpSet.value("world/clearinput", 1).toInt() ); fConnLocalEcho->setChecked( tmpSet.value("world/localecho", 1).toInt() ); // Status bar fStatExtractor->setText(tmpSet.value("statusbar/extractor").toString()); fStatFormatter->setText(tmpSet.value("statusbar/formatter").toString()); connect( fChannelList, SIGNAL(currentItemChanged(QListWidgetItem*,QListWidgetItem*)), this, SLOT(onChannelListChanged(QListWidgetItem*)) ); refreshChannels(); } void winPrefs::onChannelListChanged(QListWidgetItem *cur) { classChannel cc = pWorld->pChannels.value( cur->data(Qt::UserRole).toInt() ); fChanName->setText( cc.channelName ); fChanActivator->setPlainText( cc.channelActivator ); fChanTrigger->setPlainText( cc.channelTrigger ); fChanFormatter->setPlainText( cc.channelFormatter ); } void winPrefs::refreshChannels() { QStringList numbers; QListWidgetItem *tmpItem; classChannel cl; for(int i=0; ipChannels.size(); i++) { cl = pWorld->pChannels.value(i); tmpItem = new QListWidgetItem( fChannelList ); tmpItem->setText(cl.channelName); tmpItem->setData( Qt::UserRole, i ); } } void winPrefs::onAccepted() { // Write the configuration to disk. QSettings tmpSet("/sierra.conf", QSettings::IniFormat); // Connection settings tmpSet.setValue( "world/name", fConnWorldName->text() ); tmpSet.setValue( "world/host", fConnHost->text() ); tmpSet.setValue( "world/port", fConnPort->text().toInt() ); tmpSet.setValue( "world/autoconnect", QString::number(fConnAutoConnect->isChecked()) ); tmpSet.setValue( "world/autoreconnect", QString::number(fConnAutoReconnect->isChecked()) ); tmpSet.setValue( "world/clearinput", QString::number(fConnClearInput->isChecked()) ); tmpSet.setValue( "world/localecho", QString::number(fConnLocalEcho->isChecked()) ); // Status bar tmpSet.setValue( "statusbar/extractor", fStatExtractor->toPlainText() ); tmpSet.setValue( "statusbar/formatter", fStatFormatter->toPlainText() ); // Channels classChannel cl; tmpSet.beginWriteArray("channels"); for(int i=0; ipChannels.size(); i++) { tmpSet.setArrayIndex(i); cl = pWorld->pChannels.value(i); tmpSet.setValue("channelname", cl.channelName); } tmpSet.endArray(); }