-
Notifications
You must be signed in to change notification settings - Fork 2
/
StationFinder.h
130 lines (115 loc) · 3.6 KB
/
StationFinder.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
/*
* File: StationFinder.h
* Author: Kai Niessen
*
* Created on 9. Oktober 2015, 22:53
*/
#ifndef STATIONFINDER_H
#define STATIONFINDER_H
#include <set>
#include <vector>
#include <iterator>
#include <Window.h>
#include <Messenger.h>
#include <TextControl.h>
#include <OptionPopUp.h>
#include <HttpRequest.h>
#include <ObjectList.h>
#include <StringList.h>
#include <StatusBar.h>
#include <GridLayout.h>
#include "Station.h"
#include "StationListView.h"
#define MSG_TXSEARCH 'tSRC'
#define MSG_KWSEARCH 'kSRC'
#define MSG_BNSEARCH 'bSRC'
#define MSG_SEARCH_CLOSE 'mCLS'
#define MSG_ADD_STATION 'mADS'
#define MSG_SELECT_SERVICE 'mSSV'
#define MSG_SEARCH_BY 'mSBY'
#define MSG_VISIT_SERVICE 'mVSV'
#define MSG_SELECT_STATION 'mSLS'
#define MSG_UPDATE_STATION 'mUPS'
#define RES_BN_SEARCH 10
using namespace std;
typedef class StationFinderService* (*InstantiateFunc)();
class StationFinderServices {
public:
StationFinderServices() { };
~StationFinderServices();
static void Register(char* serviceName, InstantiateFunc);
static int CountItems();
static StationFinderService* Instantiate(char* s);
static char* Name(int i);
private:
static vector<pair<char*, InstantiateFunc> >
fServices;
};
class FindByCapability {
public:
FindByCapability(char* name);
FindByCapability(char* name, char* KeyWords, char* delimiter);
~FindByCapability();
bool HasKeyWords();
void SetKeyWords(char* KeyWords, char* delimiter);
const BStringList* KeyWords();
const char* Name();
private:
BString fName;
BStringList fKeywords;
};
class StationFinderService {
friend class StationFinderWindow;
public:
// To be overridden in specific StationFinder implementations
StationFinderService();
virtual ~StationFinderService();
static void RegisterSelf();
static StationFinderService* Instantiate();
virtual BObjectList<Station>* FindBy(int capabilityIndex,
const char* searchFor,
BLooper* resultUpdateTarget) = 0;
// Provided by ancestor class
const char* Name() const { return serviceName.String(); }
int CountCapabilities() const {
return findByCapabilities.CountItems();
};
FindByCapability* Capability(int index) const {
return findByCapabilities.ItemAt(index);
};
static void Register(char* name, InstantiateFunc instantiate);
protected:
// To be filled by specific StationFinder implementations
BString serviceName;
BUrl serviceHomePage;
BBitmap* serviceLogo;
BObjectList<FindByCapability> findByCapabilities;
// Helper functions
BBitmap* logo(BUrl url);
FindByCapability* RegisterSearchCapability(char* name);
FindByCapability* RegisterSearchCapability(char* name,
char* keyWords, char* delimiter);
};
class StationFinderWindow : public BWindow {
public:
StationFinderWindow(BWindow* parent);
virtual ~StationFinderWindow();
void MessageReceived(BMessage* msg);
virtual bool QuitRequested();
void SelectService(int index);
void SelectCapability(int index);
void DoSearch(const char* text);
private:
StationFinderService* currentService;
BMessenger* messenger;
BTextControl* txSearch;
BOptionPopUp* kwSearch;
BButton* bnSearch;
StationListView* resultView;
BButton* bnAdd;
BButton* bnVisit;
BOptionPopUp* ddServices;
BOptionPopUp* ddSearchBy;
BGridLayout* searchGrid;
};
#endif /* STATIONFINDER_H */