File indexing completed on 2024-05-12 09:06:28
0001 /*********************************************************************************** 0002 Copyright (C) 2011-2012 by Holger Danielsson (holger.danielsson@versanet.de) 0003 ***********************************************************************************/ 0004 0005 /************************************************************************** 0006 * * 0007 * This program is free software; you can redistribute it and/or modify * 0008 * it under the terms of the GNU General Public License as published by * 0009 * the Free Software Foundation; either version 2 of the License, or * 0010 * (at your option) any later version. * 0011 * * 0012 ***************************************************************************/ 0013 0014 #include "widgets/usermenuconfigwidget.h" 0015 0016 #include <KMessageBox> 0017 #include <QFileDialog> 0018 0019 #include "kileconfig.h" 0020 #include "kiledebug.h" 0021 0022 KileWidgetUsermenuConfig::KileWidgetUsermenuConfig(KileMenu::UserMenu *usermenu, QWidget *parent) 0023 : QWidget(parent), 0024 m_usermenu(usermenu) 0025 { 0026 Q_ASSERT(m_usermenu); 0027 setupUi(this); 0028 setXmlFile(m_usermenu->xmlFile()); 0029 0030 if(KileConfig::userMenuLocation() == KileMenu::UserMenu::StandAloneLocation) { 0031 m_rbStandAloneMenuLocation->setChecked(true); 0032 } 0033 else { 0034 m_rbLaTeXMenuLocation->setChecked(true); 0035 } 0036 0037 connect(m_pbInstall, SIGNAL(clicked()), this, SLOT(slotInstallClicked())); 0038 connect(m_pbRemove, SIGNAL(clicked()), this, SLOT(slotRemoveClicked())); 0039 0040 } 0041 0042 KileWidgetUsermenuConfig::~KileWidgetUsermenuConfig() 0043 { 0044 } 0045 0046 void KileWidgetUsermenuConfig::writeConfig() 0047 { 0048 const int location = (m_rbStandAloneMenuLocation->isChecked()) 0049 ? KileMenu::UserMenu::StandAloneLocation : KileMenu::UserMenu::LaTeXMenuLocation; 0050 if(KileConfig::userMenuLocation() != location) { 0051 KILE_DEBUG_MAIN << "menu position changed"; 0052 KileConfig::setUserMenuLocation(location); 0053 m_usermenu->updateGUI(); 0054 } 0055 } 0056 0057 void KileWidgetUsermenuConfig::slotInstallClicked() 0058 { 0059 KILE_DEBUG_MAIN << "install clicked"; 0060 0061 QString directory = KileMenu::UserMenu::selectUserMenuDir(); 0062 QString filter = i18n("User Menu Files (*.xml)"); 0063 0064 QString xmlfile = QFileDialog::getOpenFileName(this, i18n("Select Menu File"), directory, filter); 0065 if(xmlfile.isEmpty()) { 0066 return; 0067 } 0068 0069 if(QFile::exists(xmlfile)) { 0070 m_usermenu->installXmlFile(xmlfile); 0071 setXmlFile(xmlfile); 0072 } 0073 else { 0074 KMessageBox::error(this, i18n("File '%1' does not exist.", xmlfile)); 0075 } 0076 } 0077 0078 void KileWidgetUsermenuConfig::slotRemoveClicked() 0079 { 0080 KILE_DEBUG_MAIN << "remove clicked"; 0081 0082 m_usermenu->removeXmlFile(); 0083 setXmlFile(QString()); 0084 } 0085 0086 void KileWidgetUsermenuConfig::setXmlFile(const QString &file) 0087 { 0088 if(file.isEmpty()) { 0089 m_usermenuFile->setText(i18n("no file installed")); 0090 m_pbRemove->setEnabled(false); 0091 } 0092 else { 0093 m_usermenuFile->setText(file); 0094 m_pbRemove->setEnabled(true); 0095 } 0096 }