diff --git a/src/kalternatives.cpp b/src/kalternatives.cpp index 1568648..2f12e39 100644 --- a/src/kalternatives.cpp +++ b/src/kalternatives.cpp @@ -1,262 +1,262 @@ /*************************************************************************** * Copyright (C) 2004 by Juanjo Álvarez Martinez * * Copyright (C) 2004 by Mario Bensi * * Copyright (C) 2004 by Kevin Ottens * * Copyright (C) 2004, 2008-2009 by Pino Toscano * * Copyright (C) 2008 by Armin Berres * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program; if not, write to the * * Free Software Foundation, Inc., * * 51 Franklin Steet, Fifth Floor, Boston, MA 02111-1307, USA. * ***************************************************************************/ #include "kalternatives.h" #include "altparser.h" #include "addalternatives.h" #include "alternativemodels.h" #include "ui_propertieswindow.h" #include "aboutdata.h" #include "slavemodel.h" #include #include #include #include #include #include #include #include #include #include #include K_PLUGIN_FACTORY(KalternativesFactory, registerPlugin();) Kalternatives::Kalternatives(QWidget *parent, const QVariantList& args) : KCModule(new KAboutData(::aboutData("kalternatives", I18N_NOOP("Kalternatives"))), parent, args) { setUseRootOnlyMessage(false); int user = getuid(); if (user == 0) { m_bisRoot = true; setButtons(KCModule::Help|KCModule::Apply); } else { m_bisRoot = false; setButtons(Help); } m_ui.setupUi(this); m_ui.m_mainSplitter->setStretchFactor(1, 5); connect(m_ui.m_altList, SIGNAL(clicked(QModelIndex)), this, SLOT(slotSelectAlternativesActivated(QModelIndex))); connect(m_ui.m_bAdd, SIGNAL(clicked()), this, SLOT(slotAddClicked())); connect(m_ui.m_bDelete, SIGNAL(clicked()), this, SLOT(slotDeleteClicked())); connect(m_ui.m_bProperties, SIGNAL(clicked()), this, SLOT(slotPropertiesClicked())); - m_ui.m_bDelete->setGuiItem(KStandardGuiItem::del()); + KStandardGuiItem::assign(m_ui.m_bDelete, KStandardGuiItem::Delete); m_ui.m_bDelete->setWhatsThis(i18n("Removes the selected alternative from the current group.")); - m_ui.m_bAdd->setGuiItem(KGuiItem(i18n("&Add"), "list-add", - i18n("Adds a new alternative for the selected group."))); - m_ui.m_bProperties->setGuiItem(KGuiItem(i18n("&Properties"), "configure", - i18n("Shows the properties (path, priority, and slaves) of the selected alternative."))); + KGuiItem::assign(m_ui.m_bAdd, KGuiItem(i18n("&Add"), "list-add", + i18n("Adds a new alternative for the selected group."))); + KGuiItem::assign(m_ui.m_bProperties, KGuiItem(i18n("&Properties"), "configure", + i18n("Shows the properties (path, priority, and slaves) of the selected alternative."))); m_ui.m_statusCombo->addItem(i18nc("Automatic alternative choice", "Automatic"), Item::AutoMode); m_ui.m_statusCombo->addItem(i18nc("Manual alternative choice", "Manual"), Item::ManualMode); m_ui.m_bDelete->setEnabled(false); m_ui.m_bAdd->setEnabled(false); m_ui.m_bProperties->setEnabled(false); if(!m_bisRoot) { m_ui.m_statusCombo->setEnabled(false); } } Kalternatives::~Kalternatives() { } void Kalternatives::load() { m_itemProxyModel = new AlternativeItemProxyModel(m_ui.m_altList); slotHideAlternativesClicked(); AlternativeItemsModel *itemModel = new AlternativeItemsModel(aboutData()->componentName(), m_itemProxyModel); m_itemProxyModel->setSourceModel(itemModel); m_ui.m_altList->setModel(m_itemProxyModel); connect(itemModel, SIGNAL(dataChanged(QModelIndex, QModelIndex)), this, SLOT(slotUpdateStatusCombo())); QHeaderView *h = m_ui.m_altList->header(); h->resizeSections(QHeaderView::Stretch); h->resizeSection(0, h->sectionSizeHint(0)); connect(m_ui.m_hideAlt, SIGNAL(clicked()), this, SLOT(slotHideAlternativesClicked())); QSortFilterProxyModel *altListSorter = new QSortFilterProxyModel(m_ui.m_optionsList); altListSorter->setDynamicSortFilter(true); m_altModel = new AlternativeAltModel(itemModel, !m_bisRoot, altListSorter); altListSorter->setSourceModel(m_altModel); m_ui.m_optionsList->setModel(altListSorter); m_ui.m_optionsList->header()->setSortIndicator(0, Qt::AscendingOrder); connect(m_altModel, SIGNAL(dataChanged(QModelIndex, QModelIndex)), this, SLOT(configChanged())); connect(m_altModel, SIGNAL(rowsInserted(QModelIndex, int, int)), this, SLOT(configChanged())); connect(m_ui.m_statusCombo, SIGNAL(activated(int)), m_altModel, SLOT(statusChanged(int))); connect(m_ui.m_altList->selectionModel(), SIGNAL(selectionChanged(QItemSelection, QItemSelection)), this, SLOT(slotUpdateButtons())); connect(m_ui.m_optionsList->selectionModel(), SIGNAL(selectionChanged(QItemSelection, QItemSelection)), this, SLOT(slotUpdateButtons())); } void Kalternatives::slotSelectAlternativesActivated(const QModelIndex &index) { Item *item = index.data(AltItemRole).value(); m_altModel->setItem(item); m_ui.m_altTilte->setText(item->getName()); const int statusIndex = m_ui.m_statusCombo->findData(item->getMode()); Q_ASSERT(statusIndex != -1); m_ui.m_statusCombo->setCurrentIndex(statusIndex); slotUpdateButtons(); } void Kalternatives::slotHideAlternativesClicked() { m_itemProxyModel->setShowSingleAlternative(!m_ui.m_hideAlt->isChecked()); } void Kalternatives::slotAddClicked() { Item *item = m_ui.m_altList->currentIndex().data(AltItemRole).value(); if (item) { AddAlternatives addAlternatives(item, this); addAlternatives.exec(); if (Alternative *a = addAlternatives.alternative()) { m_altModel->addAlternative(a); } } } void Kalternatives::slotDeleteClicked() { Alternative *alt = m_ui.m_optionsList->currentIndex().data(AltAlternativeRole).value(); if (alt) { const QString messageText = i18n("Are you really sure you want to delete the alternative '%1'?", alt->getPath()); if (KMessageBox::warningYesNo(this, messageText, i18n("Delete Alternative")) == KMessageBox::Yes) { m_altModel->removeAlternative(alt); } } } void Kalternatives::slotPropertiesClicked() { Alternative *a = m_ui.m_optionsList->currentIndex().data(AltAlternativeRole).value(); if (a) { QString text; KDialog *prop = new KDialog(this); prop->setCaption(i18n("Alternative Properties")); prop->setButtons(KDialog::Close); prop->showButtonSeparator(true); Ui::PropertiesWindow propUi; propUi.setupUi(prop->mainWidget()); prop->mainWidget()->layout()->setMargin(0); connect(prop, SIGNAL(closeClicked()), prop, SLOT(deleteLater())); propUi.labelPath->setText(a->getPath()); propUi.labelDescription->setText(Alternative::prettyDescription(a)); propUi.labelPriority->setText(QString::number(a->getPriority())); if (a->slavesCount() > 0) { SlaveModel *sm = new SlaveModel(propUi.slaveView); sm->setItem(a->getParent()); sm->setAlternative(a); propUi.slaveView->setModel(sm); } else { propUi.slavesGroup->hide(); } prop->show(); } } void Kalternatives::slotUpdateStatusCombo() { Item *item = m_ui.m_altList->currentIndex().data(AltItemRole).value(); if (item) { const int statusIndex = m_ui.m_statusCombo->findData(item->getMode()); Q_ASSERT(statusIndex != -1); m_ui.m_statusCombo->setCurrentIndex(statusIndex); emit changed(true); } } void Kalternatives::slotUpdateButtons() { if (m_bisRoot) { const bool altSelected = m_ui.m_altList->selectionModel()->hasSelection(); m_ui.m_bAdd->setEnabled(altSelected); } const bool altChoiceSelected = m_ui.m_optionsList->selectionModel()->currentIndex().isValid(); m_ui.m_bProperties->setEnabled(altChoiceSelected); if (m_bisRoot) { m_ui.m_bDelete->setEnabled(altChoiceSelected); } } void Kalternatives::save() { AlternativeItemsModel *model = qobject_cast(m_itemProxyModel->sourceModel()); model->save(); emit changed( false ); } void Kalternatives::configChanged() { emit changed(true); } QString Kalternatives::quickHelp() const { return i18n("

Alternatives Configuration

\n" "This module allows you to configure the system alternatives in " "Debian/Fedora/Mandriva/openSUSE/Ubuntu distributions."); } #include diff --git a/src/mainwindow.ui b/src/mainwindow.ui index 9d131e8..b5545e3 100644 --- a/src/mainwindow.ui +++ b/src/mainwindow.ui @@ -1,275 +1,270 @@ MainWindow 0 0 615 490 0 0 0 0 Qt::Horizontal 0 0 This is a list of the available alternative groups. true false Options 0 0 If this option is active, all the alternative groups with only one alternative available will be hidden from the list. &Hide useless 0 0 75 true Status: false 0 0 <qt>The status of the current alternative: <ul> <li>Automatic: the alternative system will always choose the alternative with the highest priority, updating it (if necessary) when an alternative is installed or removed</li> <li>Manual: the choice is done manually, updated by the alternative system only when it is uninstalled</li> </ul> </qt> Qt::Horizontal QSizePolicy::Expanding 88 20 0 0 14 75 true Automake Qt::AlignCenter false Qt::Horizontal QSizePolicy::Expanding 88 20 This shows the alternatives available for the selected group. true false true true Qt::Horizontal QSizePolicy::Expanding 40 20 - + &Add - + &Properties - + &Delete - - KPushButton - QPushButton -
kpushbutton.h
-
KComboBox QComboBox
kcombobox.h
kcombobox.h kpushbutton.h kpushbutton.h kpushbutton.h