3 * Copyright (C) 2007, Rus V. Brushkoff, All rights reserved.
11 #include <FL/Fl_Preferences.H>
12 #include <cc++/socket.h>
20 #define SFINX_LOG_DEBUG 0
21 #define SFINX_LOG_NOTICE 1
22 #define SFINX_LOG_WARN 2
23 #define SFINX_LOG_ERROR 3
24 #define SFINX_LOG_FATAL 4
26 class app_specific_ui {
33 virtual ~app_specific_ui() { }
34 virtual void log(int level, const char *fmt, ...) = 0;
35 virtual void edit_slice(sfinx_slice_t *slice) = 0;
36 virtual void fill_preferences() = 0;
37 virtual void fill_unsorted_files_tree(sfinx_files_vector_t *) = 0;
38 virtual void progress(sfinx_progress_t *) = 0;
39 virtual void files_module_edit_reply(sfinx_string_t *) = 0;
40 virtual void files_module_edit(sfinx_file_t *) = 0;
41 virtual void notes_module_reply(sfinx_string_t *) = 0;
42 virtual void notes_module_edit(sfinx_note_t *) = 0;
43 virtual void alert(sfinx_string_t *) = 0;
44 virtual void search_browser(sfinx_pair_vector_t *) = 0;
45 virtual void prepare_search_info (sfinx_t *el, string &inf) = 0;
46 virtual void fill_objects_tree() = 0;
48 void lock() { big_lock.enterMutex(); }
49 void unlock() { big_lock.leaveMutex(); }
52 class x11_ui: public F_FLTK_UI, public app_specific_ui {
54 x11_ui() : F_FLTK_UI() { }
57 void log(int level, const char *fmt, ...);
58 void edit_slice(sfinx_slice_t *slice);
59 void fill_preferences();
60 void fill_unsorted_files_tree(sfinx_files_vector_t *);
61 void progress(sfinx_progress_t *);
62 void files_module_edit_reply(sfinx_string_t *);
63 void files_module_edit(sfinx_file_t *);
64 void notes_module_edit(sfinx_note_t *);
65 void notes_module_reply(sfinx_string_t *);
66 void alert(sfinx_string_t *);
67 void search_browser(sfinx_pair_vector_t *);
68 void prepare_search_info (sfinx_t *el, string &inf);
69 void fill_objects_tree();
72 class faraon_app : public F_App {
73 // available ui's for this app
78 connection_to_sfinx sfinx;
81 sfinx_pair_vector_t files_module_conf;
82 sfinx_slice_vector_t slices; // ÄÅÒÅ×Ï ÓÌÁÊÓÏ× Ó ÏÂØÅËÔÁÍÉ, Ï ËÏÔÏÒÙÈ ÚÎÁÅÔ ÓÆÉÎËÓ
83 bool slices_need_update;
85 faraon_app(int argc, char **argv, const char *name = 0,
86 const char *version = 0, const char *author = 0,
87 const char *license = 0, CommandOption *opts = 0) :
88 F_App(argc, argv, name, version, author, license, opts) {
89 files_module_conf.tid(SFINX_FILES_MODULE_CONF);
90 files_module_conf.add(FILES_MODULE_UNSORTED_PATH, new sfinx_string_t);
91 files_module_conf.add(FILES_MODULE_SORTED_TREE_PATH, new sfinx_string_t);
92 files_module_conf.add(FILES_MODULE_DESC_FILE_ENABLE, new sfinx_8bit_t);
93 files_module_conf.add(FILES_MODULE_DESC_FILE_NAME, new sfinx_string_t);
94 slices_need_update = true;
96 app_specific_ui *ui() { return dynamic_cast<app_specific_ui *>(ui_); }
98 void read_preferences();
99 void write_preferences();
101 bool connected() { return sfinx.connected(); }
103 bool refresh_slices(bool force = false) {
104 if (force || slices_need_update)
105 return sfinx.send(SFINX_OBJECTS_TREE_REQUEST, (u32_t)0xFFFFFFFF);
106 ui()->fill_objects_tree();
109 bool process_requests();
110 string slice_name(sfinx_id_t slice_id) {
111 sfinx_slice_t *slice = slices.find(slice_id);
117 t += slice->description();
121 string slice_hierarchy(sfinx_id_t sid) {
123 sfinx_slice_t *slice;
125 slice = slices.find(sid);
128 string t = slice->name();
130 t += slice->description();
132 sid = slice->parent_id;
137 for (int32_t i = h.size() - 1; i >= 0; i--) {
147 extern faraon_app *app;