~ubuntu-branches/debian/lenny/strigiapplet/lenny

« back to all changes in this revision

Viewing changes to src/kickerapplet/strigilineedit.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Mark Purcell
  • Date: 2007-11-14 21:36:22 UTC
  • mfrom: (1.2.1 upstream) (4.1.7 gutsy)
  • Revision ID: james.westby@ubuntu.com-20071114213622-rxvf3wta16gpmioj
Tags: 0.5.7-1
* New upstream release
* debian/patches/10_desktop_entry_missing_required_key.diff included
  upstream

Show diffs side-by-side

added added

removed removed

Lines of Context:
20
20
#include "strigilineedit.h"
21
21
#include "krun.h"
22
22
#include "hitsview.h"
 
23
#include "hitmenuitem.h"
 
24
#include <kpopupmenu.h>
 
25
#include <kmimetype.h>
23
26
#include <qmessagebox.h>
24
 
#include <kpopupmenu.h>
25
27
#include <qlayout.h>
26
 
#include <kmimetype.h>
27
 
#include "hitmenuitem.h"
 
28
#include <iostream>
 
29
#include <kdebug.h>
28
30
using namespace std;
29
31
 
30
32
StrigiLineEdit::StrigiLineEdit(QWidget*parent) : QLineEdit(parent),
38
40
 
39
41
    menu = new HitsView(this);
40
42
    hasmouse = false;
41
 
}
42
 
void
43
 
StrigiLineEdit::mouseMoveEvent ( QMouseEvent * e ) {
44
 
    static int i = 0;
45
 
    i = (i+1)%125+125;
46
 
    setPaletteBackgroundColor( qRgba(i,i,i,i));
47
 
    QLineEdit::mouseMoveEvent(e);
 
43
    animatedWidget = 0;
48
44
}
49
45
void
50
46
StrigiLineEdit::hideMenu() {
54
50
    }
55
51
}
56
52
void
57
 
StrigiLineEdit::leaveEvent(QEvent* e) {
58
 
    hasmouse = false;
59
 
    QTimer::singleShot( 200, this, SLOT(hideMenu()) );
60
 
    QLineEdit::leaveEvent(e);
61
 
}
62
 
void
63
 
StrigiLineEdit::enterEvent(QEvent* e) {
64
 
    if (menu->count()) {
65
 
        menu->show();
66
 
    }
67
 
    hasmouse = true;
68
 
    QLineEdit::enterEvent(e);
 
53
StrigiLineEdit::setAnimatedWidget(KAnimWidget* animWidget) {
 
54
  animatedWidget = animWidget;
69
55
}
70
56
QString
71
57
makeQuery(const QString q) {
74
60
        t += '*';
75
61
    }
76
62
    if (t.find(':') == -1) {
77
 
        t = "filename:" + t;
 
63
        t = "name:" + t;
78
64
    }
79
65
    return t;
80
66
}
92
78
    }
93
79
    lasttext = t;
94
80
    strigi.query(t);
 
81
    if (animatedWidget) {
 
82
        animatedWidget->start();
 
83
        animatedWidget->show();
 
84
    }
95
85
}
96
86
void
97
87
StrigiLineEdit::openQuery() {
122
112
StrigiLineEdit::handleHits(const QString& query, const ClientInterface::Hits& hits) {
123
113
    if (query != lasttext) return;
124
114
 
 
115
    // transform 'name:abc*' into 'abc'
 
116
    QString input = query;
 
117
    if (input.find(':') >= 0) {
 
118
        input = input.mid(input.find(':')+1);
 
119
    }
 
120
    if (input.find('*') >= 0) {
 
121
        input = input.left(input.find('*'));
 
122
    }
 
123
 
125
124
    menu->clear();
126
125
    int last = (hits.hits.size() > 10) ? 10 : hits.hits.size();
127
126
    for (int i = 0; i < last; ++i) {
128
 
        HitMenuItem* hit = createHit(hits.hits[i]);
 
127
        HitMenuItem* hit = createHit(input, hits.hits[i]);
129
128
        menu->insertItem(hit, i, i);
130
129
        menu->connectItem( i, hit, SLOT(open()) );
131
130
    }
139
138
    } else {
140
139
        menu->hide();
141
140
    }
 
141
    if (animatedWidget) {
 
142
        animatedWidget->stop();
 
143
        animatedWidget->hide();
 
144
    }
142
145
}
143
146
HitMenuItem*
144
 
StrigiLineEdit::createHit(const jstreams::IndexedDocument& hit) const {
 
147
StrigiLineEdit::createHit(const QString& input,
 
148
        const Strigi::IndexedDocument& hit) const {
145
149
    // get the appropriate icon
146
150
    QString iconname = KMimeType::mimeType(hit.mimetype.c_str())->icon(QString::null,0);
147
151
    QPixmap icon = strigiiconloader.loadIcon(iconname, KIcon::Panel);
148
152
 
149
153
    // get the filename
150
 
    QString text = "<html><b>";
 
154
    QString text = "<html>";
151
155
    QString name;
152
 
    map<string, string>::const_iterator i = hit.properties.find("title");
 
156
/*    map<string, string>::const_iterator i = hit.properties.find("audio.title");
 
157
    if (i == hit.properties.end()) {
 
158
        i = hit.properties.find("email.subject");
 
159
    }
153
160
    if (i != hit.properties.end()) {
154
161
        name = i->second;
155
 
    } else {
 
162
    } else {*/
156
163
        uint pos = hit.uri.rfind('/');
157
164
        if (pos == string::npos) {
158
165
            name = hit.uri;
159
166
        } else {
160
167
            name = hit.uri.substr(pos+1);
161
168
        }
 
169
//    }
 
170
    int index = name.find(input, 0, false);
 
171
    if (index >= 0) {
 
172
        name = name.left(index) + "<b>" + name.mid(index, input.length())
 
173
            + "</b>" + name.mid(index + input.length());
162
174
    }
163
 
    text += name + "</b> <i>" + hit.fragment.substr(0, 500);
 
175
    text += name + " <i>" + hit.fragment.substr(0, 500);
164
176
    return new HitMenuItem(icon, text, hit.uri);
165
177
}
 
178