Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

add a provider for config modules #2

Merged
merged 6 commits into from

2 participants

martin Bart Kroon
martin

added a provider for config modules (similar to krunner's services runner thingy).

(I should probably have waited until I was sober again, but it runs and compiles without warnings so w/e).

Bart Kroon tarmack merged commit 7c59bbb into from
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Apr 16, 2012
  1. martin

    fix all warnings

    sandsmark authored
Commits on Apr 17, 2012
  1. martin
  2. martin

    show type of execution

    sandsmark authored
Commits on Apr 23, 2012
  1. martin
  2. martin

    more style cleanup

    sandsmark authored
Commits on Apr 27, 2012
  1. martin

    Fix stupid bug

    sandsmark authored
This page is out of date. Refresh to see the latest.
1  CMakeLists.txt
View
@@ -13,6 +13,7 @@ providers/Paths.cpp
providers/Shell.cpp
providers/Calculator.cpp
providers/Units.cpp
+providers/ControlModules.cpp
providers/units/units.c
)
qt4_automoc(${Mangonel_SRCS})
71 Label.cpp
View
@@ -5,6 +5,7 @@
Label::Label(QWidget* parent)
{
+ Q_UNUSED(parent);
QFont* font = new QFont();
font->setPointSize(font->pointSize()+6);
this->setFont(*font);
@@ -31,23 +32,23 @@ void Label::appendText(QString text)
QString Label::completion()
{
- return this->completionText;
+ return this->m_completionText;
}
void Label::setCompletion(QString string)
{
- this->completionText = string;
+ this->m_completionText = string;
this->update();
}
QString Label::preEdit()
{
- return this->preEditText;
+ return this->m_preEditText;
}
void Label::setPreEdit(QString preEdit)
{
- this->preEditText = preEdit;
+ this->m_preEditText = preEdit;
this->update();
}
@@ -55,78 +56,78 @@ void Label::paintEvent(QPaintEvent*)
{
if (this->text().isEmpty())
return;
- painter = new QPainter(this);
- painter->setFont(this->font());
- Backpen.setBrush(QBrush());
- Frontpen.setBrush(QBrush());
- preEditPen.setBrush(QBrush());
- preEditPen.setColor(Plasma::Theme().color(Plasma::Theme::HighlightColor));
+ m_painter = new QPainter(this);
+ m_painter->setFont(this->font());
+ m_backPen.setBrush(QBrush());
+ m_frontPen.setBrush(QBrush());
+ m_preEditPen.setBrush(QBrush());
+ m_preEditPen.setColor(Plasma::Theme().color(Plasma::Theme::HighlightColor));
QColor color = Plasma::Theme().color(Plasma::Theme::TextColor);
- Frontpen.setColor(color);
+ m_frontPen.setColor(color);
color.setAlpha(100);
- Backpen.setColor(color);
+ m_backPen.setColor(color);
int lFront = this->text().length();
- int lBack = this->completionText.length();
- position = this->contentsRect().width()/2;
+ int lBack = this->m_completionText.length();
+ m_position = this->contentsRect().width()/2;
int length = QFontMetrics(this->font()).width(this->text());
bool drawComletion = false;
- int offset = this->completionText.indexOf(this->text(), 0, Qt::CaseInsensitive);
- position -= length/2;
+ int offset = this->m_completionText.indexOf(this->text(), 0, Qt::CaseInsensitive);
+ m_position -= length/2;
int advance;
if (length >= this->contentsRect().width()-60)
- position = -(length-this->width()+30);
+ m_position = -(length-this->width()+30);
if (offset >= 0)
{
drawComletion = true;
- position -= QFontMetrics(this->font()).width(this->completionText.left(offset));
+ m_position -= QFontMetrics(this->font()).width(this->m_completionText.left(offset));
}
else
{
offset = 0;
}
- Backpen = makeGradient(Backpen);
- Frontpen = makeGradient(Frontpen);
+ m_backPen = makeGradient(m_backPen);
+ m_frontPen = makeGradient(m_frontPen);
for (int index = 0; index < max(lFront, lBack); index++)
{
QChar ch;
if (drawComletion)
{
- ch = this->completionText.at(index);
+ ch = this->m_completionText.at(index);
if (index-offset < 0 or index-offset >= lFront)
- advance = paintText(ch, Backpen);
+ advance = paintText(ch, m_backPen);
else
- advance = paintText(ch, Frontpen);
+ advance = paintText(ch, m_frontPen);
}
else
{
if (index-offset >= lFront)
break;
ch = this->text().at(index);
- advance = paintText(ch, Frontpen);
+ advance = paintText(ch, m_frontPen);
}
- if (!preEditText.isEmpty())
+ if (!m_preEditText.isEmpty())
{
- if (index-lFront > 0 and index-lFront < this->preEditText.length())
+ if (index-lFront > 0 and index-lFront < this->m_preEditText.length())
{
- ch = this->preEditText.at(index-lFront);
- paintText(ch, preEditPen);
+ ch = this->m_preEditText.at(index-lFront);
+ paintText(ch, m_preEditPen);
}
}
- position += advance;
+ m_position += advance;
}
- delete painter;
- painter = 0;
+ delete m_painter;
+ m_painter = 0;
}
int Label::paintText(QChar ch, QPen pen)
{
int width = QFontMetrics(this->font()).width(ch);
- if (position+width >= 0 and position <= this->contentsRect().width())
+ if (m_position+width >= 0 and m_position <= this->contentsRect().width())
{
- painter->setPen(pen);
+ m_painter->setPen(pen);
QRect rect = this->contentsRect();
- rect.setLeft(position);
- painter->drawText(rect, QString(ch));
+ rect.setLeft(m_position);
+ m_painter->drawText(rect, QString(ch));
}
return width;
}
24 Label.h
View
@@ -9,7 +9,7 @@
class Label : public QLabel
{
Q_OBJECT
- enum side {left, right, both};
+
public:
Label(QWidget* parent = 0);
~Label();
@@ -20,18 +20,22 @@ class Label : public QLabel
QString preEdit();
void setPreEdit(QString preEdit);
void paintEvent(QPaintEvent*);
+
+signals:
+ void textChanged(QString text);
+
private:
- QString completionText;
- QString preEditText;
- QPen Frontpen;
- QPen Backpen;
- QPen preEditPen;
- int position;
- QPainter* painter;
int paintText(QChar ch, QPen pen);
QPen makeGradient(QPen pen);
-signals:
- void textChanged(QString text);
+
+ QString m_completionText;
+ QString m_preEditText;
+ QPen m_frontPen;
+ QPen m_backPen;
+ QPen m_preEditPen;
+ int m_position;
+ QPainter* m_painter;
+
};
namespace
358 Mangonel.cpp
View
@@ -16,55 +16,58 @@
#include "providers/Shell.h"
#include "providers/Calculator.h"
#include "providers/Units.h"
+#include "providers/ControlModules.h"
+#include <unistd.h>
#define WINDOW_WIDTH 220
#define WINDOW_HEIGHT 200
Mangonel::Mangonel(KApplication* app)
{
- this->setWindowFlags(Qt::Tool | Qt::FramelessWindowHint | Qt::WindowStaysOnTopHint);
- this->setContextMenuPolicy(Qt::ActionsContextMenu);
- this->setAttribute(Qt::WA_InputMethodEnabled);
- this->setAttribute(Qt::WA_MouseTracking, false);
- this->app = app;
- this->processingKey = false;
- this->apps = 0;
+ setWindowFlags(Qt::Tool | Qt::FramelessWindowHint | Qt::WindowStaysOnTopHint);
+ setContextMenuPolicy(Qt::ActionsContextMenu);
+ setAttribute(Qt::WA_InputMethodEnabled);
+ setAttribute(Qt::WA_MouseTracking, false);
+ app = app;
+ m_processingKey = false;
+ m_apps = 0;
QVBoxLayout* view = new QVBoxLayout(this);
- this->setLayout(view);
+ setLayout(view);
view->setContentsMargins(0,10,0,8);
// Setup the search feedback label.
- this->label = new Label(this);
+ m_label = new Label(this);
// Instantiate the visual feedback field.
- this->iconView = new IconView(this);
+ m_iconView = new IconView(this);
// Add all to our layout.
- view->addWidget(this->iconView);
- view->addWidget(this->label);
- this->resize(WINDOW_WIDTH, WINDOW_HEIGHT);
- this->label->setMaximumWidth(WINDOW_WIDTH - 20);
+ view->addWidget(m_iconView);
+ view->addWidget(m_label);
+ resize(WINDOW_WIDTH, WINDOW_HEIGHT);
+ m_label->setMaximumWidth(WINDOW_WIDTH - 20);
// Setup our global shortcut.
- actionShow = new KAction(QString("Show Mangonel"), this);
- actionShow->setObjectName(QString("show"));
- KShortcut shortcut = actionShow->shortcut();
+ m_actionShow = new KAction(QString("Show Mangonel"), this);
+ m_actionShow->setObjectName(QString("show"));
+ KShortcut shortcut = m_actionShow->shortcut();
shortcut.setPrimary(QKeySequence(Qt::CTRL | Qt::ALT | Qt::Key_Space));
- actionShow->setGlobalShortcut(shortcut);
- this->connect(actionShow, SIGNAL(triggered()), this, SLOT(showHide()));
+ m_actionShow->setGlobalShortcut(shortcut);
+ connect(m_actionShow, SIGNAL(triggered()), this, SLOT(showHide()));
// TODO: Get the stored history.
// Instantiate the providers.
- this->providers["applications"] = new Applications();
- this->providers["paths"] = new Paths();
- this->providers["shell"] = new Shell();
- this->providers["Calculator"] = new Calculator();
- this->providers["Units"] = new Units();
-
- this->connect(this->label, SIGNAL(textChanged(QString)), this, SLOT(getApp(QString)));
+ m_providers["applications"] = new Applications();
+ m_providers["paths"] = new Paths();
+ m_providers["shell"] = new Shell();
+ m_providers["Calculator"] = new Calculator();
+ m_providers["Units"] = new Units();
+ m_providers["ControlModules"] = new ControlModules();
+
+ connect(m_label, SIGNAL(textChanged(QString)), this, SLOT(getApp(QString)));
QAction* actionConfig = new QAction(KIcon("configure"), "Configuration", this);
- this->addAction(actionConfig);
- this->connect(actionConfig, SIGNAL(triggered(bool)), this, SLOT(showConfig()));
+ addAction(actionConfig);
+ connect(actionConfig, SIGNAL(triggered(bool)), this, SLOT(showConfig()));
}
Mangonel::~Mangonel()
@@ -80,18 +83,18 @@ bool Mangonel::event(QEvent* event)
if (mouseEvent->button() == Qt::MiddleButton)
{
event->accept();
- this->label->appendText(QApplication::clipboard()->text(QClipboard::Selection));
+ m_label->appendText(QApplication::clipboard()->text(QClipboard::Selection));
}
- else if (!this->geometry().contains(mouseEvent->globalPos()))
+ else if (!geometry().contains(mouseEvent->globalPos()))
{
- this->hide();
+ hide();
event->accept();
}
}
else if (event->type() == QEvent::ContextMenu)
{
QContextMenuEvent* menuEvent = static_cast<QContextMenuEvent*> (event);
- if (!this->geometry().contains(menuEvent->globalPos()))
+ if (!geometry().contains(menuEvent->globalPos()))
event->accept();
}
if (!event->isAccepted())
@@ -101,163 +104,165 @@ bool Mangonel::event(QEvent* event)
void Mangonel::inputMethodEvent(QInputMethodEvent* event)
{
- QString text = this->label->text();
+ QString text = m_label->text();
text.chop(event->preeditString().length());
text = text.mid(0, text.length()+event->replacementStart());
text.append(event->commitString());
if (text == "~/")
text = "";
text.append(event->preeditString());
- this->label->setPreEdit(event->preeditString());
- this->label->setText(text);
+ m_label->setPreEdit(event->preeditString());
+ m_label->setText(text);
}
void Mangonel::keyPressEvent(QKeyEvent* event)
{
int key = event->key();
IconView::direction direction = IconView::right;
Application* CurrentApp;
- if (this->processingKey)
+ if (m_processingKey)
return;
- this->processingKey = true;
+ m_processingKey = true;
switch (event->key())
{
case Qt::Key_Enter:
case Qt::Key_Return:
- this->launch();
+ launch();
case Qt::Key_Escape:
- this->hide();
+ hide();
break;
case Qt::Key_Up:
- this->historyIndex += 2;
+ m_historyIndex += 2;
case Qt::Key_Down:
- this->historyIndex -= 1;
- if (this->historyIndex >= 0)
+ m_historyIndex -= 1;
+ if (m_historyIndex >= 0)
{
- if (this->historyIndex < this->history.length())
- this->label->setText(this->history[this->historyIndex]);
+ if (m_historyIndex < m_history.length())
+ m_label->setText(m_history[m_historyIndex]);
}
else
- this->historyIndex = -1;
+ m_historyIndex = -1;
break;
case Qt::Key_Left:
direction = IconView::left;
case Qt::Key_Right:
- this->iconView->moveItems(direction);
- CurrentApp = this->iconView->selectedApp();
+ m_iconView->moveItems(direction);
+ CurrentApp = m_iconView->selectedApp();
if (CurrentApp != 0)
- this->label->setCompletion(CurrentApp->completion);
+ m_label->setCompletion(CurrentApp->completion);
break;
default:
if (key == Qt::Key_Tab)
{
- if (!this->label->completion().isEmpty())
- this->label->setText(this->label->completion());
+ if (!m_label->completion().isEmpty())
+ m_label->setText(m_label->completion());
}
else if (key == Qt::Key_Backspace)
{
- QString text = this->label->text();
+ QString text = m_label->text();
text.chop(1);
if (text == "~/")
text = "";
- this->label->setText(text);
+ m_label->setText(text);
}
else if (event->matches(QKeySequence::Paste))
{
- this->label->appendText(QApplication::clipboard()->text());
+ m_label->appendText(QApplication::clipboard()->text());
}
else
{
- this->label->appendText(event->text());
+ m_label->appendText(event->text());
}
}
- this->processingKey = false;
+ m_processingKey = false;
}
void Mangonel::getApp(QString query)
{
- this->iconView->clear();
- delete this->apps;
- this->apps = 0;
+ m_iconView->clear();
+ delete m_apps;
+ m_apps = 0;
if (query.length() > 0)
{
- this->apps = new AppList();
- this->current = -1;
- foreach(Provider* provider, this->providers)
+ m_apps = new AppList();
+ m_current = -1;
+ foreach(Provider* provider, m_providers)
{
QList<Application> list = provider->getResults(query);
foreach(Application app, list)
- this->apps->insertSorted(app);
+ m_apps->insertSorted(app);
}
- if (!this->apps->isEmpty())
+ if (!m_apps->isEmpty())
{
- for (int i = 0; i < this->apps->length(); i++)
+ for (int i = 0; i < m_apps->length(); i++)
{
- this->iconView->addProgram(this->apps->at(i));
+ m_iconView->addProgram(m_apps->at(i));
}
- this->iconView->setFirst();
- Application* CurrentApp = this->iconView->selectedApp();
+ m_iconView->setFirst();
+ Application* CurrentApp = m_iconView->selectedApp();
if (CurrentApp != 0)
- this->label->setCompletion(CurrentApp->completion);
+ m_label->setCompletion(CurrentApp->completion);
}
else
{
- this->label->setCompletion("");
+ m_label->setCompletion("");
}
}
}
void Mangonel::launch()
{
- this->history.insert(0, this->label->text());
- Application* app = this->iconView->selectedApp();
+ m_history.insert(0, m_label->text());
+ Application* app = m_iconView->selectedApp();
if (app != 0)
app->object->launch(app->program);
}
void Mangonel::showHide()
{
- if (this->isVisible())
- this->hide();
+ if (isVisible())
+ hide();
else
- this->show();
+ show();
}
void Mangonel::show()
{
- this->historyIndex = -1;
- this->resize(WINDOW_WIDTH, WINDOW_HEIGHT);
- QRect screen = this->app->desktop()->screenGeometry(this);
- int x = (screen.width() - this->geometry().width()) / 2;
- int y = (screen.height() - this->geometry().height()) / 2;
- this->move(x, y);
+ resize(WINDOW_WIDTH, WINDOW_HEIGHT);
+ m_historyIndex = -1;
+ QRect screen = qApp->desktop()->screenGeometry(this);
+ int x = (screen.width() - geometry().width()) / 2;
+ int y = (screen.height() - geometry().height()) / 2;
+ move(x, y);
QWidget::show();
- KWindowSystem::forceActiveWindow(this->winId());
- this->setFocus();
+ KWindowSystem::forceActiveWindow(winId());
+ setFocus();
}
void Mangonel::hide()
{
- this->label->setText("");
- this->iconView->clear();
- delete this->apps;
- this->apps = 0;
+ m_label->setText("");
+ m_iconView->clear();
+ delete m_apps;
+ m_apps = 0;
QWidget::hide();
}
void Mangonel::focusInEvent(QFocusEvent* event)
{
- this->grabMouse();
+ Q_UNUSED(event);
+ grabMouse();
}
void Mangonel::focusOutEvent(QFocusEvent* event)
{
- this->releaseMouse();
+ releaseMouse();
if (event->reason() != Qt::PopupFocusReason)
- this->hide();
+ hide();
}
bool Mangonel::eventFilter(QObject *object, QEvent *event)
{
+ Q_UNUSED(object);
if (event->type() == QEvent::FocusOut)
return true;
return false;
@@ -265,101 +270,102 @@ bool Mangonel::eventFilter(QObject *object, QEvent *event)
void Mangonel::showConfig()
{
- KShortcut shortcut = actionShow->globalShortcut();
+ KShortcut shortcut = m_actionShow->globalShortcut();
ConfigDialog* dialog = new ConfigDialog(this);
dialog->setHotkey(shortcut.primary());
connect(dialog, SIGNAL(hotkeyChanged(QKeySequence)), this, SLOT(setHotkey(QKeySequence)));
installEventFilter(this);
- this->releaseMouse();
+ releaseMouse();
dialog->exec();
removeEventFilter(this);
- this->activateWindow();
- this->setFocus();
+ activateWindow();
+ setFocus();
}
void Mangonel::setHotkey(const QKeySequence& hotkey)
{
KShortcut shortcut = KShortcut();
shortcut.setPrimary(hotkey);
- actionShow->setGlobalShortcut(shortcut, KAction::ShortcutTypes(KAction::ActiveShortcut|KAction::DefaultShortcut), KAction::NoAutoloading);
+ m_actionShow->setGlobalShortcut(shortcut, KAction::ShortcutTypes(KAction::ActiveShortcut|KAction::DefaultShortcut), KAction::NoAutoloading);
qDebug() << hotkey.toString();
}
-IconView::IconView(QWidget* parent) : current(-1)
+IconView::IconView(QWidget* parent) : m_current(-1)
{
- this->scene = new QGraphicsScene(QRectF(0, 0, this->rect().width()*4, this->rect().height()), this);
- this->setScene(this->scene);
- this->setFrameStyle(QFrame::NoFrame);
- this->setStyleSheet("background: transparent; border: none");
- this->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
- this->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
- this->setFocusPolicy(Qt::NoFocus);
- this->centerOn(QPoint(this->rect().width()*1.5, 0));
+ Q_UNUSED(parent);
+ m_scene = new QGraphicsScene(QRectF(0, 0, rect().width()*4, rect().height()), this);
+ setScene(m_scene);
+ setFrameStyle(QFrame::NoFrame);
+ setStyleSheet("background: transparent; border: none");
+ setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
+ setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
+ setFocusPolicy(Qt::NoFocus);
+ centerOn(QPoint(rect().width()*1.5, 0));
}
IconView::~IconView()
{
- delete this->scene;
+ delete m_scene;
}
void IconView::clear()
{
- this->scene->clear();
- this->items.clear();
- this->current = -1;
+ m_scene->clear();
+ m_items.clear();
+ m_current = -1;
}
void IconView::addProgram(Application application)
{
ProgramView* program = new ProgramView(application);
- this->items.append(program);
- this->scene->addItem(program);
+ m_items.append(program);
+ m_scene->addItem(program);
}
Application* IconView::selectedApp()
{
- if (this->current >= 0 and this->current < this->items.length())
+ if (m_current >= 0 and m_current < m_items.length())
{
- return &this->items[this->current]->application;
+ return &m_items[m_current]->application;
}
else return 0;
}
void IconView::setFirst()
{
- if (!this->items.empty())
- this->current = 0;
- this->items[this->current]->show();
- this->items[this->current]->setPos(this->rect().width() + (this->rect().width() - 128) / 2, 0);
- this->centerOn(QPoint(this->rect().width()*1.5, 0));
+ if (!m_items.empty())
+ m_current = 0;
+ m_items[m_current]->show();
+ m_items[m_current]->setPos(rect().width() + (rect().width() - 128) / 2, 0);
+ centerOn(QPoint(rect().width()*1.5, 0));
}
void IconView::moveItems(IconView::direction direction)
{
- if (this->current < 0)
+ if (m_current < 0)
return;
- int offset = this->rect().width();
+ int offset = rect().width();
int steps = 10;
int dx = offset / steps;
int index = 1;
if (direction == IconView::right)
{
- if (this->current + 1 >= this->items.length())
+ if (m_current + 1 >= m_items.length())
return;
dx = -dx;
offset *= 2;
}
else
{
- if (this->current < 1)
+ if (m_current < 1)
return;
offset = 0;
index = -1;
}
- ProgramView* itemOld = this->items[this->current];
- ProgramView* itemNew = this->items[this->current+index];
- itemNew->setPos(offset + (this->rect().width() - 128) / 2, 0);
+ ProgramView* itemNew = m_items[m_current+index];
+ ProgramView* itemOld = m_items[m_current];
+ itemNew->setPos(offset + (rect().width() - 128) / 2, 0);
itemNew->show();
int startposNew = itemNew->pos().x();
int startPosOld = itemOld->pos().x();
@@ -387,68 +393,88 @@ void IconView::moveItems(IconView::direction direction)
usleep(5000);
}
itemOld->hide();
- itemNew->setPos(this->rect().width() + (this->rect().width() - 128) / 2, 0);
- this->current += index;
- this->centerOn(QPoint(this->rect().width()*1.5, 0));
+ itemNew->setPos(rect().width() + (rect().width() - 128) / 2, 0);
+ m_current += index;
+ centerOn(QPoint(rect().width()*1.5, 0));
}
-ProgramView::ProgramView(Application application)
+ProgramView::ProgramView(Application app)
{
- this->hide();
- this->icon = 0;
- this->label = 0;
- this->block = 0;
- this->application = application;
+ hide();
+ m_icon = 0;
+ m_label = 0;
+ m_block = 0;
+ m_descriptionLabel = 0;
+ application = app;
}
ProgramView::~ProgramView()
{
- delete this->icon;
- delete this->label;
- delete this->block;
+ delete m_icon;
+ delete m_label;
+ delete m_block;
+ delete m_descriptionLabel;
}
void ProgramView::centerItems()
{
- this->icon->setPos(0, 0);
- QRectF iconRect = this->icon->boundingRect();
- QRectF labelRect = this->label->boundingRect();
- QRectF blockRect = this->block->boundingRect();
- this->block->setPos(
+ m_icon->setPos(0, 0);
+ QRectF iconRect = m_icon->boundingRect();
+ QRectF labelRect = m_label->boundingRect();
+ QRectF blockRect = m_block->boundingRect();
+ QRectF descriptionRect = m_descriptionLabel->boundingRect();
+ m_block->setPos(
qreal(iconRect.width() / 2 - blockRect.width() / 2),
qreal(iconRect.height() / 2 - blockRect.height() / 2)
);
- this->label->setPos(
+ m_label->setPos(
qreal(iconRect.width() / 2 - labelRect.width() / 2),
qreal(iconRect.height() / 2 - labelRect.height() / 2)
);
+ m_descriptionLabel->setPos(
+ qreal(iconRect.width() / 2 - descriptionRect.width() / 2),
+ qreal(iconRect.height() / 2 - descriptionRect.height() / 2 + labelRect.height())
+ );
}
void ProgramView::show()
{
- if (this->icon == 0)
- this->icon = new QGraphicsPixmapItem(KIcon(application.icon).pixmap(128), this);
- if (this->label == 0)
+ if (m_icon == 0)
+ m_icon = new QGraphicsPixmapItem(KIcon(application.icon).pixmap(128), this);
+ if (m_label == 0)
+ {
+ m_label = new QGraphicsTextItem(application.name, this);
+ if (m_label->boundingRect().width() > WINDOW_WIDTH - 40)
+ m_label->adjustSize();
+ m_label->document()->setDefaultTextOption(QTextOption(Qt::AlignCenter));
+ QColor color = Plasma::Theme().color(Plasma::Theme::TextColor);
+ m_label->setDefaultTextColor(color);
+ }
+ if (m_descriptionLabel == 0)
{
- this->label = new QGraphicsTextItem(application.name, this);
- if (this->label->boundingRect().width() > WINDOW_WIDTH - 40)
- this->label->adjustSize();
- this->label->document()->setDefaultTextOption(QTextOption(Qt::AlignCenter));
+ m_descriptionLabel = new QGraphicsTextItem("(" + application.type + ")", this);
+ if (m_descriptionLabel->boundingRect().width() > WINDOW_WIDTH - 40)
+ m_descriptionLabel->adjustSize();
+ m_descriptionLabel->document()->setDefaultTextOption(QTextOption(Qt::AlignCenter));
QColor color = Plasma::Theme().color(Plasma::Theme::TextColor);
- this->label->setDefaultTextColor(color);
+ m_descriptionLabel->setDefaultTextColor(color);
}
- if (this->block == 0)
+ if (m_block == 0)
{
- this->block = new QGraphicsRectItem(this->label->boundingRect(), this);
+ QRectF nameRect = m_label->boundingRect();
+ QRectF descriptionRect = m_descriptionLabel->boundingRect();
+ QRectF rect(nameRect.x(), nameRect.y() +10, qMax(nameRect.width(), descriptionRect.width()), nameRect.height() + descriptionRect.height() + 5);
+ m_block = new QGraphicsRectItem(rect, this);
QBrush brush = QBrush(Qt::SolidPattern);
QColor color = Plasma::Theme().color(Plasma::Theme::BackgroundColor);
brush.setColor(color);
- this->block->setBrush(brush);
- this->block->setOpacity(0.7);
+ m_block->setBrush(brush);
+ m_block->setOpacity(0.7);
}
- this->label->setZValue(10);
- this->centerItems();
+ m_label->setZValue(10);
+ m_descriptionLabel->setZValue(10);
+ centerItems();
QGraphicsItemGroup::show();
}
@@ -459,16 +485,16 @@ AppList::AppList()
AppList::~AppList()
{}
-void AppList::insertSorted(Application value)
+void AppList::insertSorted(Application item)
{
- int index = this->length() / 2;
- if (this->length() > 0)
+ int index = length() / 2;
+ if (length() > 0)
{
- int span = 1 + this->length() / 2;
- int priority = value.priority;
- int item = this->value(index).priority;
+ int span = 1 + length() / 2;
+ int priority = item.priority;
+ int item = value(index).priority;
while (!(
- priority > this->value(index - 1).priority and
+ priority > value(index - 1).priority and
priority <= item
))
{
@@ -482,15 +508,15 @@ void AppList::insertSorted(Application value)
index = 0;
break;
}
- if (index >= this->length())
+ if (index >= length())
{
- index = this->length();
+ index = length();
break;
}
- item = this->value(index).priority;
+ item = value(index).priority;
}
}
- this->insert(index, value);
+ insert(index, item);
}
45 Mangonel.h
View
@@ -23,9 +23,10 @@ class ProgramView : public QGraphicsItemGroup
void centerItems();
Application application;
private:
- QGraphicsPixmapItem* icon;
- QGraphicsTextItem* label;
- QGraphicsRectItem* block;
+ QGraphicsPixmapItem* m_icon;
+ QGraphicsTextItem* m_label;
+ QGraphicsTextItem* m_descriptionLabel;
+ QGraphicsRectItem* m_block;
};
class IconView : public QGraphicsView
@@ -42,9 +43,9 @@ class IconView : public QGraphicsView
void setFirst();
Label* label;
private:
- QList<ProgramView*> items;
- QGraphicsScene* scene;
- int current;
+ QList<ProgramView*> m_items;
+ QGraphicsScene* m_scene;
+ int m_current;
};
class AppList : public QList<Application>
@@ -64,29 +65,29 @@ class Mangonel : public Plasma::Dialog
public slots:
void show();
void hide();
+private slots:
+ void launch();
+ void getApp(QString query);
+ void showHide();
+ void showConfig();
+ void setHotkey(const QKeySequence& hotkey);
private:
- KAction* actionShow;
- bool processingKey;
- QApplication* app;
- Label* label;
- IconView* iconView;
- int historyIndex;
- QStringList history;
- QHash<QString, Provider*> providers;
- AppList* apps;
- int current;
bool event(QEvent* event);
void inputMethodEvent(QInputMethodEvent* event);
void keyPressEvent(QKeyEvent* event);
void focusInEvent(QFocusEvent* event);
void focusOutEvent(QFocusEvent* event);
bool eventFilter(QObject *object, QEvent *event);
-private slots:
- void launch();
- void getApp(QString query);
- void showHide();
- void showConfig();
- void setHotkey(const QKeySequence& hotkey);
+
+ KAction* m_actionShow;
+ bool m_processingKey;
+ Label* m_label;
+ IconView* m_iconView;
+ int m_historyIndex;
+ QStringList m_history;
+ QHash<QString, Provider*> m_providers;
+ AppList* m_apps;
+ int m_current;
};
#endif // Mangonel_H
6 Provider.h
View
@@ -4,6 +4,11 @@
#include <QObject>
#include <QVariant>
+struct popularity
+{
+ int lastUse;
+ int count;
+};
class Application;
@@ -29,6 +34,7 @@ struct Application
int priority;
QVariant program;
Provider* object; //Pointer to the search provider that provided this result.
+ QString type;
};
#endif // Provider_H
1  providers/Applications.cpp
View
@@ -68,6 +68,7 @@ QList<Application> Applications::getResults(QString query)
app.object = this;
app.program = item;
app.completion = app.name;
+ app.type = i18n("Run application");
list.append(app);
count ++;
6 providers/Applications.h
View
@@ -6,12 +6,6 @@
#include <KDE/Plasma/Applet>
#include <KDE/Plasma/DataEngine>
-struct popularity
-{
- int lastUse;
- int count;
-};
-
class AppTable : Plasma::Applet, public QHash<QString, Plasma::DataEngine::Data>
{
Q_OBJECT
2  providers/Calculator.cpp
View
@@ -5,6 +5,7 @@
#include <QApplication>
#include <QClipboard>
#include <QStringList>
+#include <klocalizedstring.h>
const QList<char> operators = (QList<char>() << '+' << '-' << '/' << '*' << '^' << '%');
@@ -38,6 +39,7 @@ QList<Application> Calculator::getResults(QString query)
result.name = QString::number(awnser, 'g', 12);
result.program = result.name;
result.object = this;
+ result.type = i18n("Calculation");
list.append(result);
}
return list;
99 providers/ControlModules.cpp
View
@@ -0,0 +1,99 @@
+#include "ControlModules.h"
+
+
+
+#include <KServiceTypeTrader>
+#include <QDebug>
+#include <krun.h>
+#include <kconfiggroup.h>
+
+ControlModules::ControlModules()
+{
+ const KConfigGroup config = KGlobal::config()->group("mangonel_controlmodules");
+
+ foreach(const QString &key, config.keyList()) {
+ QList<QVariant> values = config.readEntry<QList<QVariant> >(key, QList<QVariant>());
+ popularity pop;
+ pop.count = values[0].toInt();
+ pop.lastUse = values[1].toInt();
+ m_popularities.insert(key, pop);
+ }
+}
+
+ControlModules::~ControlModules()
+{
+ storePopularities();
+}
+
+QList< Application > ControlModules::getResults(QString term)
+{
+ QList<Application> list;
+ QString query = "exist Exec and ( (exist Keywords and '%1' ~subin Keywords) or (exist GenericName and '%1' ~~ GenericName) or (exist Name and '%1' ~~ Name) or ('%1' ~~ Exec) )";
+ query = query.arg(term);
+ KService::List services = KServiceTypeTrader::self()->query("KCModule", query);
+ foreach(const KService::Ptr &service, services) {
+ if (service->noDisplay())
+ continue;
+
+ Application app;
+ app.name = service->name();
+ app.completion = app.name;
+ app.icon = service->icon();
+ app.object = this;
+ app.program = service->exec();
+ app.type = i18n("Open control module");
+
+
+ // Same calculation as app
+ if (m_popularities.contains(service->exec())) {
+ app.priority = time(NULL) - m_popularities[service->exec()].lastUse;
+ app.priority -= 3600 * m_popularities[service->exec()].count;
+ } else {
+ app.priority = time(NULL);
+ }
+
+ list.append(app);
+ }
+ return list;
+}
+
+int ControlModules::launch(QVariant selected)
+{
+ QString exec = selected.toString();
+ popularity pop;
+ if (m_popularities.contains(exec)) {
+ pop = m_popularities[exec];
+ pop.lastUse = time(NULL);
+ pop.count++;
+ } else {
+ pop.lastUse = time(NULL);
+ pop.count = 0;
+ }
+ m_popularities[exec] = pop;
+
+
+ storePopularities();
+
+ if (KRun::run(exec, KUrl::List(), 0))
+ return 0;
+ else
+ return 1;
+}
+
+void ControlModules::storePopularities()
+{
+ KConfigGroup config = KGlobal::config()->group("mangonel_controlmodules");
+
+ foreach(const QString &key, m_popularities.keys()) {
+ QList<QVariant> values;
+ values.append(m_popularities[key].count);
+ values.append(m_popularities[key].lastUse);
+ config.writeEntry(key, values);
+ }
+ config.sync();
+}
+
+
+#include "ControlModules.moc"
+
+// kate: indent-mode cstyle; space-indent on; indent-width 4;
25 providers/ControlModules.h
View
@@ -0,0 +1,25 @@
+#ifndef CONTROLMODULES_H
+#define CONTROLMODULES_H
+
+#include "Provider.h"
+
+#include <kservicegroup.h>
+
+class ControlModules : public Provider
+{
+ Q_OBJECT
+public:
+ ControlModules();
+ ~ControlModules();
+
+public slots:
+ QList<Application> getResults(QString query);
+ int launch(QVariant selected);
+
+private:
+ void storePopularities();
+ QHash<QString, popularity> m_popularities;
+};
+
+#endif//CONTROLMODULES_H
+// kate: indent-mode cstyle; space-indent on; indent-width 4;
2  providers/Paths.cpp
View
@@ -2,6 +2,7 @@
#include <QDir>
#include <KDE/KFileItem>
+#include <klocale.h>
Paths::Paths()
@@ -52,6 +53,7 @@ QList<Application> Paths::getResults(QString query)
result.priority = priority;
result.object = this;
result.program = path.absoluteFilePath();
+ result.type = i18n("Open path");
priority ++;
list.append(result);
}
4 providers/Shell.cpp
View
@@ -3,16 +3,15 @@
#include <stdlib.h>
#include <QDBusInterface>
#include <QDir>
+#include <klocalizedstring.h>
Shell::Shell()
{
- int len;
this->index = QHash<QString, QString>();
foreach(QString dir, getPathEnv())
{
this->index.unite(walkDir(dir));
- len = this->index.size();
}
}
@@ -35,6 +34,7 @@ QList<Application> Shell::getResults(QString query)
app.icon = "system-run";
app.object = this;
app.program = this->index[key] + args;
+ app.type = i18n("Shell command");
list.append(app);
}
6 providers/Units.cpp
View
@@ -5,6 +5,7 @@
#include <QRegExp>
#include <QClipboard>
#include <QApplication>
+#include <klocalizedstring.h>
Units::Units()
{}
@@ -15,7 +16,7 @@ Units::~Units()
QList< Application > Units::getResults(QString query)
{
QList<Application> list = QList<Application>();
- QRegExp patern = QRegExp("(.+)\\s+(?:\=|to|is)\\s+(.+)$", Qt::CaseInsensitive);
+ QRegExp patern = QRegExp("(.+)\\s+(?:\\=|to|is)\\s+(.+)$", Qt::CaseInsensitive);
if (query.contains(patern) && patern.captureCount() == 2)
{
Application result = Application();
@@ -39,7 +40,8 @@ QList< Application > Units::getResults(QString query)
result.name = QString(units_check_exception());
result.program = result.name;
}
- list.append(result);
+ result.type = i18n("Unit conversion");
+ list.append(result);
}
return list;
}
72 providers/units/units.c
View
@@ -35,15 +35,16 @@
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
+#include<ctype.h>
/* Define a few useful constants */
-static char *primitivestring="-primitive";
-static char powerchar='^';
-static char *unitNameCharacters="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
-static char *separators=" \t*-";
-static char *divider="/";
-static char *validchars="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789. \t*^/+-";
+static const char *primitivestring="-primitive";
+static const char powerchar='^';
+static const char *unitNameCharacters="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
+static const char *separators=" \t*-";
+static const char *divider="/";
+static const char *validchars="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789. \t*^/+-";
/*
@@ -96,7 +97,6 @@ static Prefix *proot = NULL;
*-----------------------------------------------------------------
*/
-static int isspace(char character);
/* String manipulation functions */
static char *stringcopy _ANSI_ARGS_((CONST char *string));
static char *stringset _ANSI_ARGS_((char *target, CONST char *source));
@@ -105,18 +105,17 @@ static char *stringappend _ANSI_ARGS_((char *target, CONST char *source));
/* Unit and Prefix creation/destruction */
static Unit *createunit _ANSI_ARGS_(());
static void destroyunit _ANSI_ARGS_((Unit *u));
-static Prefix *createprefix _ANSI_ARGS_((char *name, double factor));
+static Prefix *createprefix _ANSI_ARGS_((const char *name, double factor));
/* Unit untility functions */
-static Unit *reduceUnit _ANSI_ARGS_((char *unitString));
+static Unit *reduceUnit _ANSI_ARGS_((const char *unitString));
static Unit *sortUnitList _ANSI_ARGS_(( Unit *u));
static void cancelUnitList _ANSI_ARGS_((Unit **numerator, Unit **denominator));
static int unitInitialize _ANSI_ARGS_(());
/* Error Generation Functions */
-static void throw_exception _ANSI_ARGS_((char *message));
-static void throw_exception1 _ANSI_ARGS_((char *message, char *arg1));
-static void throw_exception2 _ANSI_ARGS_((char *message, char *arg1, char *arg2));
+static void throw_exception1 _ANSI_ARGS_((const char *message, const char *arg1));
+static void throw_exception2 _ANSI_ARGS_((const char *message, const char *arg1, const char *arg2));
/*
@@ -132,12 +131,6 @@ static void throw_exception2 _ANSI_ARGS_((char *message, char *arg1, char *arg2)
*-----------------------------------------------------------------
*/
-/* Return >0 if the provided char is a space. */
-static int isspace(char character)
-{
- return (character == ' ');
-}
-
/* Make a new copy of a string */
static char *stringcopy(string)
CONST char *string; /* string to copy */
@@ -225,7 +218,7 @@ static Unit *createunit() {
* Prefixes are only created, not destroyed
*/
static Prefix *createprefix(name, factor)
- char *name; /* name for prefix */
+ const char *name; /* name for prefix */
double factor; /* multiple factor (e.g., 1.0E3) */
{
Prefix *p;
@@ -263,16 +256,9 @@ static Prefix *createprefix(name, factor)
static char error_message[ERRMSGLEN];
static int error_status = 0;
-static void throw_exception(message)
- char *message; /* message string */
-{
- strncpy(error_message, message,ERRMSGLEN) ;
- error_status = 1;
-}
-
static void throw_exception1(message, arg1)
- char *message; /* message string */
- char *arg1; /* argument to format into message */
+ const char *message; /* message string */
+ const char *arg1; /* argument to format into message */
{
if ( strlen(message) + strlen(arg1) < ERRMSGLEN-1 ) {
sprintf(error_message, message, arg1) ;
@@ -283,9 +269,9 @@ static void throw_exception1(message, arg1)
}
static void throw_exception2(message, arg1, arg2)
- char *message; /* message string */
- char *arg1; /* argument to format into message */
- char *arg2; /* argument to format into message */
+ const char *message; /* message string */
+ const char *arg1; /* argument to format into message */
+ const char *arg2; /* argument to format into message */
{
if ( strlen(message) + strlen(arg1) + strlen(arg2) < ERRMSGLEN-1 ) {
sprintf(error_message, message, arg1, arg2) ;
@@ -481,19 +467,19 @@ char *units_reduce ( unitString )
/* local functions */
static Unit *reduceUnit ( unitString )
- char *unitString; /* unit string to reduce */
+ const char *unitString; /* unit string to reduce */
{
Unit *u; /* new reduced unit */
char *cp; /* for traversing strings */
char *tokenString; /* tokenized copy of unitString */
- int numeratorlen; /* for splitting unitString */
+ unsigned int numeratorlen; /* for splitting unitString */
char *subunit; /* one token from tokenString */
char *subunitcopy; /* copy of subunit, for plural chopping */
double factor; /* value of constant factor subunits */
int numerflag = 1; /* boolean switch between numer/denom */
int exponent; /* subunit exponent value */
int e; /* loop counter for exponents */
- int len, pos; /* for separating prefix and unit name */
+ unsigned int len, pos; /* for separating prefix and unit name */
Unit *up1, *up2; /* for searching the unit list */
Prefix *p; /* for walking prefix list */
Unit *usub; /* new subunits (added to u) */
@@ -994,7 +980,7 @@ static void cancelUnitList(numerator, denominator)
/* SI Base Units */
/* SI Supplementary Units */
-static char *baseUnits[] = {
+static const char *baseUnits[] = {
"meter",
"gram",
"second",
@@ -1005,7 +991,7 @@ static char *baseUnits[] = {
NULL};
/* SI Derived Units with Special Names */
-static char *derivedUnits[] = {
+static const char *derivedUnits[] = {
"radian", "meter/meter",
"steradian", "meter^2/meter^2",
"hertz", "/second",
@@ -1029,7 +1015,7 @@ static char *derivedUnits[] = {
NULL, NULL};
/* Non-SI units */
-static char *nonSIUnits[] = {
+static const char *nonSIUnits[] = {
"angstrom", "1.0E-10meter",
"astronomicalUnit", "1.495979E11meter",
"atmosphere", "1.01325E5pascal",
@@ -1069,7 +1055,7 @@ static char *nonSIUnits[] = {
/* Abbreviations */
-static char *abbreviations[] = {
+static const char *abbreviations[] = {
"m", "meter",
"g", "gram",
"s", "second",
@@ -1098,7 +1084,7 @@ static char *abbreviations[] = {
"Sv", "sievert",
NULL, NULL};
-static char *nonSIabbreviations[] = {
+static const char *nonSIabbreviations[] = {
"AU", "astronomicalUnit",
"ft", "foot",
"gr", "grain",
@@ -1138,7 +1124,7 @@ static char *nonSIabbreviations[] = {
*
*------------------------------------------------------------*/
-static char *prefixList[] = {
+static const char *prefixList[] = {
"yotta", "1e24",
"zetta", "1e21",
"exa", "1e18",
@@ -1183,9 +1169,9 @@ static char *prefixList[] = {
NULL, NULL};
static int unitInitialize() {
- Unit *u, *up;
- Prefix *p, *pp;
- char **name, **value;
+ Unit *u, *up = 0;
+ Prefix *p, *pp = 0;
+ const char **name, **value;
/* Load the Prefix List */
for (name=prefixList,value=name+1; *name!=NULL; name+=2,value+=2) {
Something went wrong with that request. Please try again.