~ubuntu-branches/ubuntu/intrepid/kdesdk/intrepid-updates

« back to all changes in this revision

Viewing changes to kbabel/kbabel/kbbookmarkhandler.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Jonathan Riddell
  • Date: 2008-05-28 10:11:43 UTC
  • mto: This revision was merged to the branch mainline in revision 37.
  • Revision ID: james.westby@ubuntu.com-20080528101143-gzc3styjz1b70zxu
Tags: upstream-4.0.80
ImportĀ upstreamĀ versionĀ 4.0.80

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* ****************************************************************************
2
 
  This file is part of KBabel
3
 
 
4
 
  Copyright (C) 2002 by Marco Wegner <mail@marcowegner.de>
5
 
 
6
 
  This program is free software; you can redistribute it and/or modify
7
 
  it under the terms of the GNU General Public License as published by
8
 
  the Free Software Foundation; either version 2 of the License, or
9
 
  (at your option) any later version.
10
 
 
11
 
  This program is distributed in the hope that it will be useful,
12
 
  but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 
  GNU General Public License for more details.
15
 
 
16
 
  You should have received a copy of the GNU General Public License
17
 
  along with this program; if not, write to the Free Software
18
 
  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
19
 
 
20
 
  In addition, as a special exception, the copyright holders give
21
 
  permission to link the code of this program with any edition of
22
 
  the Qt library by Trolltech AS, Norway (or with modified versions
23
 
  of Qt that use the same license as Qt), and distribute linked
24
 
  combinations including the two.  You must obey the GNU General
25
 
  Public License in all respects for all of the code used other than
26
 
  Qt. If you modify this file, you may extend this exception to
27
 
  your version of the file, but you are not obligated to do so.  If
28
 
  you do not wish to do so, delete this exception statement from
29
 
  your version.
30
 
 
31
 
**************************************************************************** */
32
 
 
33
 
 
34
 
#include <qpopupmenu.h>
35
 
#include <qregexp.h>
36
 
#include <qstring.h>
37
 
 
38
 
#include "kbbookmarkhandler.h"
39
 
 
40
 
 
41
 
// implementation of KBabelBookmark
42
 
KBabelBookmark::KBabelBookmark(int msgindex, QString msgtext)
43
 
{
44
 
  _msgindex = msgindex;
45
 
  if (msgtext.length() > 32) {
46
 
    msgtext.truncate(32);
47
 
    msgtext.append("...");
48
 
  }
49
 
 
50
 
  // insert one '&' before every consecutive group of ampersands to keep the
51
 
  // first of these from acting either as accelerator or mask in the menu
52
 
  QRegExp rx("&+");
53
 
  int pos = msgtext.find(rx);
54
 
  while (pos >= 0) {
55
 
    msgtext.insert(pos, '&');
56
 
    pos = msgtext.find(rx, pos + rx.matchedLength() + 1);
57
 
  }
58
 
 
59
 
  _msgtext = msgtext;
60
 
}
61
 
 
62
 
int KBabelBookmark::msgindex() const
63
 
{
64
 
  return _msgindex;
65
 
}
66
 
 
67
 
QString KBabelBookmark::msgtext() const
68
 
{
69
 
  return _msgtext;
70
 
}
71
 
 
72
 
 
73
 
// implementation of KBabelBookmarkHandler
74
 
KBabelBookmarkHandler::KBabelBookmarkHandler(QPopupMenu* menu)
75
 
{
76
 
  _menu = menu;
77
 
  _list.setAutoDelete(true);
78
 
}
79
 
 
80
 
void KBabelBookmarkHandler::addBookmark(KBabelBookmark* b)
81
 
{
82
 
  // check if a bookmark to the current msgid exists already
83
 
  QPtrListIterator<KBabelBookmark> it(_list);
84
 
  KBabelBookmark* temp;
85
 
 
86
 
  while((temp = it.current()) != 0) {
87
 
    ++it;
88
 
    if (temp->msgindex() == b->msgindex()) {
89
 
      // gotcha
90
 
      delete b;
91
 
      return;
92
 
    }
93
 
  }
94
 
 
95
 
  // if it's okay then add the bookmark
96
 
  _list.append(b);
97
 
  _menu->insertItem(QString("#%1 - %2").arg(b->msgindex()).arg(b->msgtext()),
98
 
    this, SIGNAL(signalBookmarkSelected(int)), 0, b->msgindex());
99
 
}
100
 
 
101
 
void KBabelBookmarkHandler::addBookmark(int msgindex, QString msgtext)
102
 
{
103
 
  addBookmark(new KBabelBookmark(msgindex, msgtext));
104
 
}
105
 
 
106
 
void KBabelBookmarkHandler::setBookmarks(QPtrList<KBabelBookmark> list)
107
 
{
108
 
  QPtrListIterator<KBabelBookmark> it(list);
109
 
  KBabelBookmark* temp;
110
 
 
111
 
  while((temp = it.current()) != 0) {
112
 
    ++it;
113
 
    addBookmark(temp->msgindex(), temp->msgtext()); // make deep copy
114
 
  }
115
 
}
116
 
 
117
 
QPtrList<KBabelBookmark> KBabelBookmarkHandler::bookmarks() const
118
 
{
119
 
  return _list;
120
 
}
121
 
 
122
 
void KBabelBookmarkHandler::slotClearBookmarks()
123
 
{
124
 
  while (!_list.isEmpty()) {
125
 
    KBabelBookmark* b = _list.first();
126
 
    _menu->removeItem(b->msgindex());
127
 
    _list.remove(b);
128
 
  }
129
 
}
130
 
 
131
 
#include "kbbookmarkhandler.moc"