~ubuntu-branches/ubuntu/vivid/fbreader/vivid-proposed

« back to all changes in this revision

Viewing changes to fbreader/src/fbreader/SearchActions.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Joey Hess
  • Date: 2008-01-23 16:51:07 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20080123165107-5q19etahzd72c33a
Tags: 0.8.12-3
* Add libzlui-maemo which allows using fbreader on the maemo platform, on
  Debian. Thanks, Riku Voipio. Closes: #462299
* makefiles/arch/maemo.mk: Don't build with -thumb. (Riku)
* Loosen dependency versions some more, so it only depends on the current
  upstream version or higher, ignoring the Debian revision.
* Use binary:Version instead of deprecated Source-Version.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright (C) 2004-2008 Geometer Plus <contact@geometerplus.com>
 
3
 *
 
4
 * This program is free software; you can redistribute it and/or modify
 
5
 * it under the terms of the GNU General Public License as published by
 
6
 * the Free Software Foundation; either version 2 of the License, or
 
7
 * (at your option) any later version.
 
8
 *
 
9
 * This program is distributed in the hope that it will be useful,
 
10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
12
 * GNU General Public License for more details.
 
13
 *
 
14
 * You should have received a copy of the GNU General Public License
 
15
 * along with this program; if not, write to the Free Software
 
16
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
 
17
 * 02110-1301, USA.
 
18
 */
 
19
 
 
20
#include <ZLDialogManager.h>
 
21
#include <ZLDialog.h>
 
22
#include <ZLStringUtil.h>
 
23
 
 
24
#include <ZLTextView.h>
 
25
 
 
26
#include "FBReader.h"
 
27
#include "FBReaderActions.h"
 
28
 
 
29
SearchAction::SearchAction(FBReader &fbreader) : FBAction(fbreader) {
 
30
}
 
31
 
 
32
bool SearchAction::isVisible() {
 
33
        return !fbreader().currentView().isNull();
 
34
}
 
35
 
 
36
void SearchAction::run() {
 
37
        ZLTextView &textView = (ZLTextView&)*fbreader().currentView();
 
38
 
 
39
        shared_ptr<ZLDialog> searchDialog = ZLDialogManager::instance().createDialog(ZLResourceKey("textSearchDialog"));
 
40
 
 
41
        searchDialog->addOption(ZLResourceKey("text"), fbreader().SearchPatternOption);
 
42
        searchDialog->addOption(ZLResourceKey("ignoreCase"), fbreader().SearchIgnoreCaseOption);
 
43
        searchDialog->addOption(ZLResourceKey("wholeText"), fbreader().SearchInWholeTextOption);
 
44
        searchDialog->addOption(ZLResourceKey("backward"), fbreader().SearchBackwardOption);
 
45
        if (textView.hasMultiSectionModel()) {
 
46
                searchDialog->addOption(ZLResourceKey("currentSection"), fbreader().SearchThisSectionOnlyOption);
 
47
        }
 
48
        searchDialog->addButton(ZLResourceKey("go"), true);
 
49
        searchDialog->addButton(ZLDialogManager::CANCEL_BUTTON, false);
 
50
 
 
51
        if (searchDialog->run()) {
 
52
                searchDialog->acceptValues();
 
53
                std::string pattern = fbreader().SearchPatternOption.value();
 
54
                ZLStringUtil::stripWhiteSpaces(pattern);
 
55
                fbreader().SearchPatternOption.setValue(pattern);
 
56
                textView.search(
 
57
                        pattern,
 
58
                        fbreader().SearchIgnoreCaseOption.value(),
 
59
                        fbreader().SearchInWholeTextOption.value(),
 
60
                        fbreader().SearchBackwardOption.value(),
 
61
                        fbreader().SearchThisSectionOnlyOption.value()
 
62
                );
 
63
        }
 
64
}
 
65
 
 
66
FindNextAction::FindNextAction(FBReader &fbreader) : FBAction(fbreader) {
 
67
}
 
68
 
 
69
bool FindNextAction::isEnabled() {
 
70
        shared_ptr<ZLView> view = fbreader().currentView();
 
71
        return (!view.isNull()) && ((ZLTextView&)*view).canFindNext();
 
72
}
 
73
 
 
74
void FindNextAction::run() {
 
75
        ((ZLTextView&)*fbreader().currentView()).findNext();
 
76
}
 
77
 
 
78
FindPreviousAction::FindPreviousAction(FBReader &fbreader) : FBAction(fbreader) {
 
79
}
 
80
 
 
81
bool FindPreviousAction::isEnabled() {
 
82
        shared_ptr<ZLView> view = fbreader().currentView();
 
83
        return (!view.isNull()) && ((ZLTextView&)*view).canFindPrevious();
 
84
}
 
85
 
 
86
void FindPreviousAction::run() {
 
87
        ((ZLTextView&)*fbreader().currentView()).findPrevious();
 
88
}