Show invite menu in wlm chat window immediately
[kdenetwork.git] / kopete / plugins / pipes / pipespreferences.cpp
blob4a7b06a4c6a356fcc5b4ab83d548d058bc847a37
1 /*
2 pipespreferences.cpp
4 Copyright (c) 2007 by Charles Connell <charles@connells.org>
6 Kopete (c) 2007 by the Kopete developers <kopete-devel@kde.org>
8 *************************************************************************
9 * *
10 * This program is free software; you can redistribute it and/or modify *
11 * it under the terms of the GNU General Public License as published by *
12 * the Free Software Foundation; either version 2 of the License, or *
13 * (at your option) any later version. *
14 * *
15 *************************************************************************
17 #include "pipespreferences.h"
19 #include <QHeaderView>
20 #include <QCheckBox>
21 #include <QComboBox>
23 #include <kpluginfactory.h>
24 #include <kfiledialog.h>
26 #include "ui_pipesprefsbase.h"
27 #include "pipesmodel.h"
28 #include "pipesdelegate.h"
29 #include "pipesplugin.h"
30 #include "pipesconfig.h"
32 K_PLUGIN_FACTORY ( PipesPreferencesFactory, registerPlugin<PipesPreferences>(); )
33 K_EXPORT_PLUGIN ( PipesPreferencesFactory ( "kcm_kopete_pipes" ) )
35 PipesPreferences::PipesPreferences ( QWidget *parent, const QVariantList &args )
36 : KCModule ( PipesPreferencesFactory::componentData(), parent, args )
38 mPrefs = new Ui::PipesPrefsUI;
39 mPrefs->setupUi (this);
41 mPrefs->pipesList->setSortingEnabled (false);
43 mModel = new PipesModel (this);
44 PipesDelegate * delegate = new PipesDelegate (this);
46 mPrefs->pipesList->setModel (mModel);
47 mPrefs->pipesList->setItemDelegate (delegate);
49 mPrefs->pipesList->horizontalHeader()->setStretchLastSection (true);
50 mPrefs->pipesList->verticalHeader()->hide();
52 connect (mPrefs->addButton, SIGNAL (clicked()), this, SLOT(slotAdd()));
53 connect (mPrefs->removeButton, SIGNAL (clicked()), this, SLOT(slotRemove()));
54 connect (mModel, SIGNAL (dataChanged(const QModelIndex&, const QModelIndex&)), this, SLOT(slotListChanged()));
55 connect (mModel, SIGNAL (modelReset()), this, SLOT (slotListChanged()));
57 slotListChanged();
60 PipesPreferences::~PipesPreferences()
62 delete mPrefs;
65 void PipesPreferences::load()
67 PipesConfig::self()->load();
68 mModel->setPipes (PipesConfig::pipes());
70 emit KCModule::changed(false);
73 void PipesPreferences::save()
75 PipesConfig::setPipes (mModel->pipes());
76 PipesConfig::self()->save();
78 emit KCModule::changed(false);
81 // We get a filename, then fill out a PipeOptions class with some default data,
82 // then pass it to the file.
83 void PipesPreferences::slotAdd()
85 QString filePath = KFileDialog::getOpenFileName( KUrl ("kfiledialog:///pipesplugin"), QString(), this, i18n ("Select a Program or Script to Pipe Messages Through"));
86 if (filePath.isEmpty())
87 return;
88 PipesPlugin::PipeOptions pipe;
89 pipe.uid = QUuid::createUuid();
90 pipe.path = filePath;
91 pipe.direction = PipesPlugin::BothDirections;
92 pipe.pipeContents = PipesPlugin::HtmlBody;
93 pipe.enabled = true;
94 mModel->addPipe (pipe);
97 void PipesPreferences::slotRemove()
99 mModel->removeRow( mPrefs->pipesList->currentIndex().row(), QModelIndex() );
102 // when the data changes, we tell the view to resize itself
103 void PipesPreferences::slotListChanged()
105 mPrefs->pipesList->resizeColumnToContents(PipesDelegate::EnabledColumn);
106 mPrefs->pipesList->resizeColumnToContents(PipesDelegate::DirectionColumn);
107 mPrefs->pipesList->resizeColumnToContents(PipesDelegate::ContentsColumn);
108 changed();