From kde-commits Mon Jun 30 22:20:03 2008 From: =?utf-8?q?Ivan=20=C4=8Cuki=C4=87?= Date: Mon, 30 Jun 2008 22:20:03 +0000 To: kde-commits Subject: KDE/kdeplasmoids/applets/lancelot Message-Id: <1214864403.751469.21786.nullmailer () svn ! kde ! org> X-MARC-Message: https://marc.info/?l=kde-commits&m=121486441315112 SVN commit 826539 by ivan: Search is returned to L M +27 -18 app/src/LancelotWindow.cpp M +7 -0 app/src/LancelotWindow.h M +37 -53 app/src/models/Runner.cpp M +4 -3 app/src/models/Runner.h M +3 -3 app/src/ui/LancelotWindowBase.xml M +0 -2 libs/lancelot/widgets/ExtenderButton.cpp --- trunk/KDE/kdeplasmoids/applets/lancelot/app/src/LancelotWindow.cpp #826538:826539 @@ -47,6 +47,9 @@ #include +#include +#include + #define sectionsWidth 128 #define windowHeightDefault 500 #define mainWidthDefault 422 @@ -212,10 +215,16 @@ setupModels(); - /* Dirty hack to get an edit box before Qt 4.4 :: begin */ - // editSearch->setParent(this); - // editSearch->installEventFilter(this); - /* Dirty hack to get an edit box before Qt 4.4 :: end */ + /* TODO: Convert this to PUCK generated code */ + editSearch = new Plasma::LineEdit(); + editSearch->setParentItem(m_root); + editSearch->nativeWidget()->setClearButtonShown(true); + editSearch->nativeWidget()->setClickMessage(i18n("Search")); + editSearch->show(); + layoutSearch->addItem(editSearch, + Lancelot::NodeLayout::NodeCoordinate(0.0, 0.5, 0, 0), + Lancelot::NodeLayout::NodeCoordinate(1.0, 0.5, 0, INFINITY) + ); instance->activateAll(); @@ -237,10 +246,10 @@ connect(buttonSystemLogout, SIGNAL(activated()), this, SLOT(systemLogout())); connect(buttonSystemSwitchUser, SIGNAL(activated()), this, SLOT(systemSwitchUser())); - //connect(editSearch, - // SIGNAL(textChanged(const QString &)), - // this, SLOT(search(const QString &)) - //); + connect(editSearch->widget(), + SIGNAL(textChanged(const QString &)), + this, SLOT(search(const QString &)) + ); loadConfig(); } @@ -401,9 +410,9 @@ void LancelotWindow::search(const QString & string) { - // if (editSearch->text() != string) { - // editSearch->setText(string); - // } + if (editSearch->text() != string) { + editSearch->setText(string); + } m_searchString = string; @@ -594,13 +603,13 @@ bool LancelotWindow::eventFilter(QObject * object, QEvent * event) { -// if ((object == editSearch) && (event->type() == QEvent::KeyPress)) { -// QKeyEvent * keyEvent = static_cast(event); -// if (keyEvent->key() == Qt::Key_Escape) { -// lancelotHide(true); -// return true; -// } -// } + if (event->type() == QEvent::KeyPress) { + QKeyEvent * keyEvent = static_cast(event); + if (keyEvent->key() == Qt::Key_Escape) { + lancelotHide(true); + return true; + } + } return QWidget::eventFilter(object, event); } --- trunk/KDE/kdeplasmoids/applets/lancelot/app/src/LancelotWindow.h #826538:826539 @@ -36,6 +36,11 @@ class ResizeBordersPanel; } +namespace Plasma +{ + class LineEdit; +} + class LancelotWindow: public QWidget, public Ui::LancelotWindowBase { Q_OBJECT @@ -154,6 +159,8 @@ Plasma::Corona * m_corona; QVBoxLayout * m_layout; + Plasma::LineEdit * editSearch; + QTimer m_hideTimer; QString m_searchString; --- trunk/KDE/kdeplasmoids/applets/lancelot/app/src/models/Runner.cpp #826538:826539 @@ -1,6 +1,5 @@ /* * Copyright (C) 2007 Ivan Cukic - * Copyright (C) 2006 Aaron Seigo * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser/Library General Public License version 2, @@ -21,6 +20,7 @@ #include "Runner.h" #include #include +#include #include #include @@ -32,7 +32,12 @@ { // m_runners = Plasma::AbstractRunner::load(this); - load(); + m_runnerManager = new Plasma::RunnerManager(this); + connect( + m_runnerManager, SIGNAL(matchesChanged(const QList&)), + this, SLOT(setQueryMatches(const QList&)) + ); + setSearchString(QString()); } Runner::~Runner() @@ -47,69 +52,48 @@ void Runner::setSearchString(const QString & search) { m_searchString = search.trimmed(); - load(); -} -void Runner::load() -{/* - m_items.clear(); - - int matchCount = 0; - if (m_searchString.isEmpty()) { + m_items.clear(); add( - "Search string is empty", - "Enter something to search for", - NULL, + i18n("Search string is empty"), + i18n("Enter something to search for"), + KIcon("help-hint"), QVariant() ); - return; + } else { + m_runnerManager->launchQuery(search); } +} - m_context.resetSearchTerm(m_searchString); - //m_context.addStringCompletions(m_executions); +// Code taken from KRunner Runner::setQueryMatches +void Runner::setQueryMatches(const QList< Plasma::QueryMatch > & m) +{ + m_items.clear(); - foreach (Plasma::AbstractRunner* runner, m_runners) { - runner->match(&m_context); - } + QList < Plasma::QueryMatch > matches = m; + QMutableListIterator < Plasma::QueryMatch > newMatchIt(matches); - QList < QList < Plasma::SearchMatch * > > matchLists; - matchLists << m_context.matches(); - // << m_context.exactMatches() - // << m_context.possibleMatches(); - - foreach (QList < Plasma::SearchMatch * > matchList, matchLists) { - foreach (Plasma::SearchMatch * action, matchList) { - add( - action->text(), - action->runner()->objectName(), - action->icon(), - qVariantFromValue((void *)action) - ); - - ++matchCount; - } + // first pass: we try and match up items with existing ids (match persisitence) + while (newMatchIt.hasNext()) { + Plasma::QueryMatch match = newMatchIt.next(); + add( + match.text(), + match.subtext(), + match.icon(), + match.id() + ); } -*/} +} -void Runner::activate(int index) -{/* - Plasma::SearchMatch * action = (Plasma::SearchMatch *) - m_items[index].data.value< void * >(); +void Runner::load() +{ +} - Q_ASSERT(action); - - if (!action->isEnabled()) { - return; - } - - if (action->type() == Plasma::SearchMatch::InformationalMatch) { - changeLancelotSearchString(action->data().toString()); - } else { - action->exec(&m_context); - hideLancelotWindow(); - } -*/ +void Runner::activate(int index) +{ + m_runnerManager->run(m_items[index].data.value< QString >()); + hideLancelotWindow(); } } // namespace Models --- trunk/KDE/kdeplasmoids/applets/lancelot/app/src/models/Runner.h #826538:826539 @@ -21,7 +21,8 @@ #define LANCELOTAPP_MODELS_RUNNER_H_ #include "BaseModel.h" -#include +#include +#include namespace Models { @@ -35,6 +36,7 @@ public Q_SLOTS: void setSearchString(const QString & search); + void setQueryMatches(const QList &matches); protected: void activate(int index); @@ -42,8 +44,7 @@ private: QString m_searchString; - Plasma::AbstractRunner::List m_runners; - Plasma::RunnerContext m_context; + Plasma::RunnerManager * m_runnerManager; }; } // namespace Models --- trunk/KDE/kdeplasmoids/applets/lancelot/app/src/ui/LancelotWindowBase.xml #826538:826539 @@ -225,7 +225,7 @@ Lancelot__CardLayout:cardName="documents" > - + - + checkable) return; d->checked = !d->checked; update();