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 fill_objects_tree() = 0;
46 void lock() { big_lock.enterMutex(); }
47 void unlock() { big_lock.leaveMutex(); }
50 class x11_ui: public F_FLTK_UI, public app_specific_ui {
52 x11_ui() : F_FLTK_UI() { }
55 void log(int level, const char *fmt, ...);
56 void edit_slice(sfinx_slice_t *slice);
57 void fill_preferences();
58 void fill_unsorted_files_tree(sfinx_files_vector_t *);
59 void progress(sfinx_progress_t *);
60 void files_module_edit_reply(sfinx_string_t *);
61 void files_module_edit(sfinx_file_t *);
62 void notes_module_edit(sfinx_note_t *);
63 void notes_module_reply(sfinx_string_t *);
64 void alert(sfinx_string_t *);
65 void search_browser(sfinx_pair_vector_t *);
67 void fill_objects_tree();
70 class faraon_app : public F_App {
71 // available ui's for this app
76 connection_to_sfinx sfinx;
79 sfinx_pair_vector_t files_module_conf;
80 sfinx_slice_vector_t slices; // ÄÅÒÅ×Ï ÓÌÁÊÓÏ× Ó ÏÂØÅËÔÁÍÉ, Ï ËÏÔÏÒÙÈ ÚÎÁÅÔ ÓÆÉÎËÓ
81 bool slices_need_update;
83 faraon_app(int argc, char **argv, const char *name = 0,
84 const char *version = 0, const char *author = 0,
85 const char *license = 0, CommandOption *opts = 0) :
86 F_App(argc, argv, name, version, author, license, opts) {
87 files_module_conf.tid(SFINX_FILES_MODULE_CONF);
88 files_module_conf.add(FILES_MODULE_UNSORTED_PATH, new sfinx_string_t);
89 files_module_conf.add(FILES_MODULE_SORTED_TREE_PATH, new sfinx_string_t);
90 files_module_conf.add(FILES_MODULE_DESC_FILE_ENABLE, new sfinx_8bit_t);
91 files_module_conf.add(FILES_MODULE_DESC_FILE_NAME, new sfinx_string_t);
92 slices_need_update = true;
94 app_specific_ui *ui() { return dynamic_cast<app_specific_ui *>(ui_); }
96 void read_preferences();
97 void write_preferences();
99 bool connected() { return sfinx.connected(); }
101 bool refresh_slices(bool force = false) {
102 if (force || slices_need_update)
103 return sfinx.send(SFINX_OBJECTS_TREE_REQUEST, (u32_t)0xFFFFFFFF);
104 ui()->fill_objects_tree();
107 void prepare_search_info(sfinx_t *el, string &inf);
108 bool process_requests();
109 string slice_name(sfinx_id_t slice_id) {
110 sfinx_slice_t *slice = slices.find(slice_id);
116 t += slice->description();
120 string slice_hierarchy(sfinx_id_t sid) {
122 sfinx_slice_t *slice;
124 slice = slices.find(sid);
127 string t = slice->name();
129 t += slice->description();
131 sid = slice->parent_id;
136 for (int32_t i = h.size() - 1; i >= 0; i--) {
144 string slice_hierarchy_path(sfinx_id_t sid) {
146 sfinx_slice_t *slice;
148 slice = slices.find(sid);
151 h.push_back("/" + slice->directory_);
152 sid = slice->parent_id;
156 for (int32_t i = h.size() - 1; i >= 0; i--) {
164 extern faraon_app *app;