~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): Eugene V. Lyubimkin
  • Date: 2008-06-17 23:01:53 UTC
  • mfrom: (1.1.3 upstream)
  • Revision ID: james.westby@ubuntu.com-20080617230153-a16c45tq69j8geru
Tags: 0.8.17-11
* debian/control:
  - Enhanced all ZLibrary descriptions, not the main one.
  - Done some renaming to use canonical names of libraries and toolkits in
    decriptions, as suggested by developers-reference:
    'qt' -> 'Qt', 'gtk' -> 'GTK+', 'zlibrary' -> 'ZLibrary'.
  - Bump 'Depends' on quilt to (>= 0.24).
* debian/rules:
  - Included quilt makefile instead of quilt makefile instead
    of copy&paste'ing it.
* debian/fbreader.links:
  - Added this file to relay on dh_link's work instead of using 'ln -sf'
    directly in the debian/rules.

Show diffs side-by-side

added added

removed removed

Lines of Context:
25
25
 
26
26
#include "FBReader.h"
27
27
#include "FBReaderActions.h"
28
 
 
29
 
SearchAction::SearchAction(FBReader &fbreader) : FBAction(fbreader) {
 
28
#include "../options/FBOptions.h"
 
29
 
 
30
#include <set>
 
31
 
 
32
static const std::string SEARCH = "Search";
 
33
static const std::string PATTERN = "Pattern";
 
34
 
 
35
class SearchPatternEntry : public ZLComboOptionEntry {
 
36
 
 
37
public:
 
38
        SearchPatternEntry(SearchAction &action);
 
39
 
 
40
        const std::string &initialValue() const;
 
41
        const std::vector<std::string> &values() const;
 
42
        void onAccept(const std::string &value);
 
43
 
 
44
private:
 
45
        SearchAction &myAction;
 
46
        mutable std::vector<std::string> myValues;
 
47
};
 
48
 
 
49
SearchPatternEntry::SearchPatternEntry(SearchAction &action) : ZLComboOptionEntry(true), myAction(action) {
 
50
}
 
51
 
 
52
const std::string &SearchPatternEntry::initialValue() const {
 
53
        return values()[0];
 
54
}
 
55
 
 
56
const std::vector<std::string> &SearchPatternEntry::values() const {
 
57
        if (myValues.empty()) {
 
58
                // TODO: implement
 
59
                myValues.push_back(myAction.SearchPatternOption.value());
 
60
                for (int i = 1; i < 6; ++i) {
 
61
                        std::string pattern = PATTERN;
 
62
                        ZLStringUtil::appendNumber(pattern, i);
 
63
                        std::string value = ZLStringOption(FBCategoryKey::SEARCH, SEARCH, pattern, "").value();
 
64
                        if (!value.empty()) {
 
65
                                myValues.push_back(value);
 
66
                        }
 
67
                }
 
68
        }
 
69
        return myValues;
 
70
}
 
71
 
 
72
void SearchPatternEntry::onAccept(const std::string &value) {
 
73
        std::string v = value;
 
74
        ZLStringUtil::stripWhiteSpaces(v);
 
75
        if (!v.empty() && (v != values()[0])) {
 
76
                myAction.SearchPatternOption.setValue(v);
 
77
                int index = 1;
 
78
                for (std::vector<std::string>::const_iterator it = myValues.begin(); (index < 6) && (it != myValues.end()); ++it) {
 
79
                        if (*it != v) {
 
80
                                std::string pattern = PATTERN;
 
81
                                ZLStringUtil::appendNumber(pattern, index++);
 
82
                                ZLStringOption(FBCategoryKey::SEARCH, SEARCH, pattern, "").setValue(*it);
 
83
                        }
 
84
                }
 
85
        }
 
86
}
 
87
 
 
88
SearchAction::SearchAction(FBReader &fbreader) : FBAction(fbreader),
 
89
        SearchBackwardOption(FBCategoryKey::SEARCH, SEARCH, "Backward", false),
 
90
        SearchIgnoreCaseOption(FBCategoryKey::SEARCH, SEARCH, "IgnoreCase", true),
 
91
        SearchInWholeTextOption(FBCategoryKey::SEARCH, SEARCH, "WholeText", false),
 
92
        SearchThisSectionOnlyOption(FBCategoryKey::SEARCH, SEARCH, "ThisSectionOnly", false),
 
93
        SearchPatternOption(FBCategoryKey::SEARCH, SEARCH, PATTERN, "") {
30
94
}
31
95
 
32
96
bool SearchAction::isVisible() {
38
102
 
39
103
        shared_ptr<ZLDialog> searchDialog = ZLDialogManager::instance().createDialog(ZLResourceKey("textSearchDialog"));
40
104
 
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);
 
105
        searchDialog->addOption(ZLResourceKey("text"), new SearchPatternEntry(*this));
 
106
        searchDialog->addOption(ZLResourceKey("ignoreCase"), SearchIgnoreCaseOption);
 
107
        searchDialog->addOption(ZLResourceKey("wholeText"), SearchInWholeTextOption);
 
108
        searchDialog->addOption(ZLResourceKey("backward"), SearchBackwardOption);
45
109
        if (textView.hasMultiSectionModel()) {
46
 
                searchDialog->addOption(ZLResourceKey("currentSection"), fbreader().SearchThisSectionOnlyOption);
 
110
                searchDialog->addOption(ZLResourceKey("currentSection"), SearchThisSectionOnlyOption);
47
111
        }
48
112
        searchDialog->addButton(ZLResourceKey("go"), true);
49
113
        searchDialog->addButton(ZLDialogManager::CANCEL_BUTTON, false);
50
114
 
51
115
        if (searchDialog->run()) {
52
116
                searchDialog->acceptValues();
53
 
                std::string pattern = fbreader().SearchPatternOption.value();
54
 
                ZLStringUtil::stripWhiteSpaces(pattern);
55
 
                fbreader().SearchPatternOption.setValue(pattern);
56
117
                textView.search(
57
 
                        pattern,
58
 
                        fbreader().SearchIgnoreCaseOption.value(),
59
 
                        fbreader().SearchInWholeTextOption.value(),
60
 
                        fbreader().SearchBackwardOption.value(),
61
 
                        fbreader().SearchThisSectionOnlyOption.value()
 
118
                        SearchPatternOption.value(),
 
119
                        SearchIgnoreCaseOption.value(),
 
120
                        SearchInWholeTextOption.value(),
 
121
                        SearchBackwardOption.value(),
 
122
                        SearchThisSectionOnlyOption.value()
62
123
                );
63
124
        }
64
125
}