/*************************************************************************** * Copyright (C) 2005 by Daniel Stöckel * * the_docter@gmx.net * * * * 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., * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ #include "configdialogimpl.h" #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include "menulistviewitem.h" #include "servicemenu.h" #include "configuration.h" #include #include #include ConfigDialogImpl::ConfigDialogImpl(QWidget* parent, const char* name, WFlags fl) : ConfigDialog(parent,name,fl), configChanged(false), grabbing(0), curListView(0), mMenus(true) { new QListBoxPixmap(listBox,MainBarIcon("kommando",KIcon::SizeLarge),"Menu"); new QListBoxPixmap(listBox,MainBarIcon("configure_shortcuts",KIcon::SizeLarge),"Shortcuts"); new QListBoxPixmap(listBox,MainBarIcon("colors",KIcon::SizeLarge),"Appearance"); listBox->setSelected(listBox->topItem(),true); connect(kKeyButton1,SIGNAL(capturedShortcut(const KShortcut&)),this,SLOT(slotShortcutChanged(const KShortcut&)) ); addService->setPopup(new ServiceMenu(this, SLOT(slotAddService(KService*)), SLOT(slotAddServiceGroup(KServiceGroup*)), addService)); } void ConfigDialogImpl::readConfig() { Config& config = Config::getSingleton(); navButtonSize->setCurrentText(QString::number(config.navButtonSize())); menuButtonSize->setCurrentText(QString::number(config.menuButtonSize())); menuRadiusSpinbox->setValue(config.menuRadius()); if(config.scheme()=="none"){ customCheckbox->setChecked(true); } else { customCheckbox->setChecked(false); schemeCombobox->setCurrentText(config.scheme()); } menuViewComboBox->clear(); initView(); iconButton->resetIcon(); iconButton->setEnabled(false); commandoEdit->clear(); commandoEdit->setEnabled(false); remove->setEnabled(false); kColorButton1->setColor(config.tintColor()); opacitySlider->setValue(static_cast(config.opacity()*100)); kKeyButton1->setText(config.Shortcut()); } void ConfigDialogImpl::setChanged(bool state) { configChanged=state; emit changed(state); } /*$SPECIALIZATION$*/ void ConfigDialogImpl::slotRemoveListViewClicked() { if(curListView->appName() != "default"){ if (curListView->childCount() > 0) setChanged(true); lists->removeWidget(curListView); mMenus.remove(curListView); curListView = 0; menuViewComboBox->removeItem(menuViewComboBox->currentItem()); menuViewComboBox->setCurrentText("default"); slotChangeListView("default"); } } void ConfigDialogImpl::slotNewListViewClicked() { newListView->setEnabled(false); grabbing = true; setCursor(Qt::CrossCursor); grabMouse(); } void ConfigDialogImpl::slotChangeListView(const QString& appname) { KommandoView* temp = mMenus.getViewOrDefault(appname); if(temp == curListView){ return; } if(temp && curListView){ curListView->disconnect(); } if(temp){ curListView = temp; lists->raiseWidget(curListView); connect(curListView, SIGNAL(clicked(QListViewItem*)), this, SLOT(slotMenuViewClicked(QListViewItem*))); slotMenuViewClicked(curListView->selectedItem()); } } void ConfigDialogImpl::slotButtonDownPressed() { QListViewItem* item = curListView->selectedItem(); if(item!=NULL){ QListViewItem* below = item->itemBelow(); while((below!=NULL)&&(item->parent()!=below->parent())){ below=below->itemBelow(); } if(below!=NULL){ item->moveItem(below); } } setChanged(true); } void ConfigDialogImpl::slotButtonUpPressed() { QListViewItem* item = curListView->selectedItem(); if(item!=NULL){ QListViewItem* above = item->itemAbove(); while((above!=NULL)&&(item->parent()!=above->parent())){ above=above->itemAbove(); } if(above!=NULL){ above->moveItem(item); } } setChanged(true); } void ConfigDialogImpl::slotCustomSizeCheckboxToggled(bool mode) { schemeCombobox->setEnabled(!mode); menuRadiusSpinbox->setEnabled(mode); menuButtonSize->setEnabled(mode); navButtonSize->setEnabled(mode); if(!mode){ slotSchemeComboboxChanged(schemeCombobox->currentText()); } else { Config::getSingleton().setScheme("none"); } setChanged(true); } void ConfigDialogImpl::slotSchemeComboboxChanged(const QString& scheme) { Config& config=Config::getSingleton(); if(scheme=="Tiny"){ config.setMenuRadius(72); config.setNavButtonSize(22); config.setMenuButtonSize(16); } else if(scheme=="Small"){ config.setMenuRadius(100); config.setNavButtonSize(32); config.setMenuButtonSize(22); } if(scheme=="Normal"){ config.setMenuRadius(132); config.setNavButtonSize(32); config.setMenuButtonSize(32); } if(scheme=="Big"){ config.setMenuRadius(200); config.setNavButtonSize(48); config.setMenuButtonSize(48); } config.setScheme(scheme); navButtonSize->setCurrentText(QString::number(config.navButtonSize())); menuButtonSize->setCurrentText(QString::number(config.menuButtonSize())); menuRadiusSpinbox->setValue(config.menuRadius()); setChanged(true); } void ConfigDialogImpl::slotMenuRadiusSpinboxChanged(int size) { Config::getSingleton().setMenuRadius(size); setChanged(true); } void ConfigDialogImpl::slotNavButtonSizeChanged(const QString& size) { Config::getSingleton().setNavButtonSize(size.toShort()); setChanged(true); } void ConfigDialogImpl::slotMenuButtonSizeChanged(const QString& size) { Config::getSingleton().setMenuButtonSize(size.toShort()); setChanged(true); } void ConfigDialogImpl::slotCommandoTyped(const QString& commando) { if (curListView->selectedItem() && curListView->selectedItem()->text(1) != commando) { curListView->selectedItem()->setText(1,commando); setChanged(true); } } void ConfigDialogImpl::slotMenuViewClicked(QListViewItem* item) { MenuListViewItem* temp = static_cast(item); if(item == 0){ iconButton->resetIcon(); iconButton->setEnabled(false); commandoEdit->clear(); commandoEdit->setEnabled(false); remove->setEnabled(false); } else { if(temp->iconPath()!=NULL){ iconButton->setIcon(temp->iconPath()); } else { iconButton->resetIcon(); } if(temp->type()==MenuListViewItem::Button){ commandoEdit->setEnabled(true); commandoEdit->setText(temp->text(1)); } else { commandoEdit->setEnabled(false); } iconButton->setEnabled(true); remove->setEnabled(true); } } void ConfigDialogImpl::slotNewIcon() { MenuListViewItem* temp = static_cast(curListView->selectedItem()); temp->setIconPath(iconButton->icon()); setChanged(true); } void ConfigDialogImpl::slotRemoveClicked() { QListViewItem* temp = curListView->selectedItem()->nextSibling(); delete curListView->selectedItem(); curListView->setSelected(temp,true); if(temp==NULL){ remove->setEnabled(false); } setChanged(true); } void ConfigDialogImpl::slotAddButtonClicked() { createEntry("Button"); commandoEdit->setEnabled(true); } void ConfigDialogImpl::slotAddMenuClicked() { createEntry("Menu"); commandoEdit->setEnabled(false); } void ConfigDialogImpl::createEntry(const QString& kind) { QListViewItem* parent=NULL; QListViewItem* newItem; MenuListViewItem* selected =static_cast(curListView->selectedItem()); MenuListViewItem::ItemType type; if(selected!=NULL){ if(selected->type()==MenuListViewItem::Menu){ parent=selected; selected=selected->lastChild(); } else if(selected->parent()!=NULL){ parent=selected->parent(); } } else { selected=static_cast(curListView->lastItem()); } if(kind=="Menu"){ type=MenuListViewItem::Menu; } else { type=MenuListViewItem::Button; } if(parent!=NULL){ newItem=new MenuListViewItem(parent,selected,kind,type); } else { newItem=new MenuListViewItem(curListView,selected,kind,type); } newItem->setOpen(true); curListView->setSelected(newItem,true); iconButton->resetIcon(); iconButton->setEnabled(true); remove->setEnabled(true); commandoEdit->clear(); setChanged(true); } void ConfigDialogImpl::slotListBoxClicked(QListBoxItem* item) { if(item!=NULL){ if(item->text()=="Menu"){ pages->raiseWidget(0); } else if(item->text()=="Shortcuts"){ pages->raiseWidget(1); } else if(item->text()=="Appearance"){ pages->raiseWidget(2); } } } void ConfigDialogImpl::slotDefaultsClicked() { Config::getSingleton().setDefaultValues(); readConfig(); setChanged(true); } void ConfigDialogImpl::slotApplyClicked() { Config& config = Config::getSingleton(); config.fromConfigDlg(mMenus); config.writeConfigFile(); kapp->dcopClient()->send("kded", "kommandod", "reparseConfiguration()", QString::null); setChanged(false); } void ConfigDialogImpl::slotShortcutChanged(const KShortcut & cut ) { if(!KKeyChooser::checkGlobalShortcutsConflict(cut,true,this)){ kKeyButton1->setText(cut.toString()); Config::getSingleton().setShortcut(cut.toString()); setChanged(true); } } void ConfigDialogImpl::slotColorButtonClicked(const QColor& color) { Config::getSingleton().setTintColor(color); setChanged(true); } void ConfigDialogImpl::slotOpacitySliderChanged( int value ) { Config::getSingleton().setOpacity(static_cast(value)/100.0f); setChanged(true); } void ConfigDialogImpl::slotAddService(KService* service) { slotAddButtonClicked(); QString commando = service->exec(); commando.remove(QRegExp(" %.\\b")); commando.remove(" -caption \"%c\""); commandoEdit->setText(commando); curListView->selectedItem()->setText(1, commando); iconButton->setIcon(service->icon()); slotNewIcon(); } void ConfigDialogImpl::slotAddServiceGroup(KServiceGroup* group) { slotAddMenuClicked(); iconButton->setIcon(group->icon()); slotNewIcon(); KServiceGroup::List list = group->entries(true, true, false, false); KServiceGroup::List::ConstIterator it = list.begin(); for (; it != list.end(); ++it) { KSycocaEntry *e = *it; if (e->isType(KST_KServiceGroup)) { KServiceGroup::Ptr g(static_cast(e)); if (g->childCount() > 0) { slotAddServiceGroup(g); } } else if (e->isType(KST_KService)) { slotAddService(static_cast(e)); } } } bool ConfigDialogImpl::event( QEvent * evt ) { if(grabbing){ switch(evt->type()){ case QEvent::MouseButtonPress: switch(static_cast(evt)->button()){ case Qt::LeftButton: releaseMouse(); listViewFromClick(); grabbing = false; break; default: releaseMouse(); grabbing = false; } break; case QEvent::KeyPress: if(static_cast(evt)->key() == Qt::Key_Escape){ releaseMouse(); grabbing = false; } break; default: return ConfigDialog::event(evt); } if(!grabbing){ newListView->setEnabled(true); unsetCursor(); } } return ConfigDialog::event(evt); } void ConfigDialogImpl::initView( ) { mMenus.clear(); curListView = 0; Config::getSingleton().toListView(mMenus, lists); for(KommandoView* it = mMenus.first(); it != 0; it = mMenus.next()){ menuViewComboBox->insertItem(it->appName()); } menuViewComboBox->setCurrentText("default"); slotChangeListView("default"); } void ConfigDialogImpl::listViewFromClick( ) { Window rep_root, rep_child; int rep_rootx, rep_rooty; unsigned int rep_mask; int mousex, mousey; Display* dpy = qt_xdisplay(); Window win = qt_xrootwin(); XClassHint hint; hint.res_class = 0; hint.res_name = 0; //Get mouse coursor position and the application name of the window under the coursor XQueryPointer (dpy, win, &rep_root, &rep_child, &rep_rootx, &rep_rooty, &mousex, &mousey, &rep_mask); rep_child = XmuClientWindow(dpy,rep_child); if(XGetClassHint(dpy,rep_child,&hint) != 0){ if(!mMenus.contains(hint.res_class)){ KommandoView* view = new KommandoView(lists, hint.res_class); lists->addWidget(view); mMenus.append(view); menuViewComboBox->insertItem(hint.res_class,0); menuViewComboBox->setCurrentItem(0); slotChangeListView(hint.res_class); } } if(hint.res_class){ XFree(hint.res_class); } if(hint.res_name){ XFree(hint.res_name); } } #include "configdialogimpl.moc"