text_tasks.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 #include "plugin_render_result.h"
00028
00029 #include "log.h"
00030 #include "text_tasks.h"
00031 #include "text_view.h"
00032
00033 namespace text
00034 {
00035
00036 InitializationTask::InitializationTask(TextView *view)
00037 : text_view(view)
00038 {
00039 }
00040
00041 InitializationTask::~InitializationTask()
00042 {
00043 }
00044
00045 void InitializationTask::execute()
00046 {
00047 text_view->initialize();
00048 }
00049
00050 DeinitializationTask::DeinitializationTask(TextView *view)
00051 : text_view(view)
00052 {
00053 }
00054
00055 DeinitializationTask::~DeinitializationTask()
00056 {
00057 }
00058
00059 void DeinitializationTask::execute()
00060 {
00061 text_view->deinitialize();
00062 }
00063
00064 PaginationTask::PaginationTask(TextView *view, const Position& _start, bool _is_child)
00065 : text_view(view), start_pos(_start), is_child(_is_child)
00066 {
00067 }
00068
00069 PaginationTask::~PaginationTask()
00070 {
00071 }
00072
00073 void PaginationTask::execute()
00074 {
00075 if (!is_child)
00076 {
00077
00078 LOGPRINTF("About to send pagination start signal.");
00079 text_view->pagination_start_signal.broadcast(1);
00080 }
00081
00082 bool pagination_done = false;
00083 while (!is_aborted())
00084 {
00085 if (text_view->paginate(start_pos))
00086 {
00087
00088 pagination_done = true;
00089 break;
00090 }
00091 }
00092
00093 if (pagination_done)
00094 {
00095
00096 unsigned int total_pages = text_view->get_page_count();
00097 unsigned int current_page = text_view->get_current_page_index();
00098 LOGPRINTF("About to send pagination done signal.");
00099 text_view->pagination_end_signal.broadcast(current_page, total_pages);
00100 }
00101 else
00102 {
00103
00104 LOGPRINTF("Pagination aborted...");
00105 abort_signal.broadcast(start_pos);
00106 }
00107 }
00108
00109
00110 PaginationAbortTask::PaginationAbortTask(TextView *view)
00111 : text_view(view)
00112 {
00113 TRACEFUNCTION();
00114 }
00115
00116 PaginationAbortTask::~PaginationAbortTask()
00117 {
00118 TRACEFUNCTION();
00119 }
00120
00121 void PaginationAbortTask::execute()
00122 {
00123 TRACEFUNCTION();
00124
00125
00126
00127
00128
00129
00130
00131
00132 }
00133
00134 RenderTask::RenderTask(unsigned int _id,
00135 TextView *_view,
00136 const Position& _pos,
00137 void *_user_data,
00138 unsigned char *_bmp)
00139 : id(_id)
00140 , text_view(_view)
00141 , start_pos(_pos)
00142 , user_data(_user_data)
00143 , bmp(_bmp)
00144 {
00145 }
00146
00147 RenderTask::~RenderTask()
00148 {
00149 }
00150
00151 void RenderTask::execute()
00152 {
00153 Position end_pos = text_view->render(bmp, start_pos);
00154
00155
00156 text_view->render_done_signal.broadcast(id, start_pos, end_pos, user_data);
00157 }
00158
00159 SearchTask::SearchTask(TextModel *_model, SearchContext* _sc)
00160 : text_model(_model), sc(_sc)
00161 {
00162 }
00163
00164 SearchTask::~SearchTask()
00165 {
00166 }
00167
00168 void SearchTask::execute()
00169 {
00170 std::vector<Range> result_ranges;
00171 bool search_done = false;
00172 while (!is_aborted() &&
00173 text_model->get_aborting_search_task_id() != sc->search_id)
00174 {
00175 if (text_model->search(result_ranges, sc))
00176 {
00177
00178
00179 search_done = true;
00180 break;
00181 }
00182 }
00183
00184 if (is_aborted())
00185 {
00186 LOGPRINTF("Search task is aborted by another task...");
00187 abort_signal.broadcast(sc);
00188 }
00189
00190 if (search_done)
00191 {
00192
00193 text_model->search_done_signal.broadcast(result_ranges, sc);
00194 }
00195 else
00196 {
00197
00198 LOGPRINTF("Search task is aborted by user...");
00199 }
00200 }
00201
00202 }
00203