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 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362
|
/* Copyright (C) 2004 MySQL AB
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
#ifndef _MQRESULTSETVIEW_H_
#define _MQRESULTSETVIEW_H_
#include "myqb.h"
#include <gtkmm/box.h>
#include <gtkmm/treeview.h>
#include <gtkmm/treemodel.h>
#include <gtkmm/eventbox.h>
#include <gtkmm/separator.h>
#include <gtkmm/button.h>
#include <gtkmm/liststore.h>
#include <gtkmm/treestore.h>
#include <gtkmm/scrolledwindow.h>
#include <gtkmm/menu.h>
#include "MGResultSetModel.h"
#include "MGCellRendererBlob.h"
class MQQueryDispatcher;
class MQHistory;
class MQGlobalQueryParameters;
class MQQueryParameters;
class MGBlobEditor;
class MQResultSetView : public Gtk::EventBox, public MGBlobDelegate {
public:
typedef sigc::signal2<void,MQResultSetView*,bool> QueryStartedSignal;
typedef sigc::signal1<void,MQResultSetView*> QueryFinishedSignal;
typedef sigc::signal2<void,MQResultSetView*,MYSQL*> QueryMoreDataSignal;
typedef sigc::signal1<void,MQResultSetView*> ActivateSignal;
typedef sigc::signal1<void,MQResultSetView*> RowChangedSignal;
protected:
Gtk::VBox _box;
class ModelColumns : public Gtk::TreeModel::ColumnRecord
{
public:
std::vector<Gtk::TreeModelColumn<Glib::ustring> *> columns;
std::vector<Gtk::TreeModelColumn<Glib::ustring> *> bgcolors;
std::vector<Gtk::TreeModelColumn<gpointer> *> blobs;
Gtk::TreeModelColumn<bool> editable;
Gtk::TreeModelColumn<Glib::RefPtr<Gdk::Pixbuf> > indicator;
// columns are like:
// ( text|blob color )* editable indicator
void add_text_column()
{
Gtk::TreeModelColumn<Glib::ustring> *col= new Gtk::TreeModelColumn<Glib::ustring>();
columns.push_back(col);
add(*col);
Gtk::TreeModelColumn<Glib::ustring> *color= new Gtk::TreeModelColumn<Glib::ustring>();
bgcolors.push_back(color);
add(*color);
}
void add_blob_column()
{
Gtk::TreeModelColumn<gpointer> *col= new Gtk::TreeModelColumn<gpointer>();
blobs.push_back(col);
add(*col);
Gtk::TreeModelColumn<Glib::ustring> *color= new Gtk::TreeModelColumn<Glib::ustring>();
bgcolors.push_back(color);
add(*color);
}
void add_extra_columns()
{
// add new columns after this line and update MGResultSetModel
add(editable);
add(indicator);
}
~ModelColumns()
{
for (int i= 0; i < (int)columns.size(); i++)
delete columns[i];
for (int i= 0; i < (int)bgcolors.size(); i++)
delete bgcolors[i];
for (int i= 0; i < (int)blobs.size(); i++)
delete blobs[i];
}
};
class MessageColumns : public Gtk::TreeModel::ColumnRecord
{
public:
MessageColumns()
{
add(icon);
add(errornum);
add(message);
add(row);
}
Gtk::TreeModelColumn<Glib::RefPtr<Gdk::Pixbuf> > icon;
Gtk::TreeModelColumn<int> errornum;
Gtk::TreeModelColumn<int> row;
Gtk::TreeModelColumn<Glib::ustring> message;
} _msg_columns;
class ExplainColumns : public Gtk::TreeModel::ColumnRecord
{
public:
ExplainColumns()
{
add(select_type);
add(table);
add(type);
add(possible_keys);
add(key);
add(key_len);
add(ref);
add(rows);
add(extra);
}
Gtk::TreeModelColumn<Glib::ustring> select_type;
Gtk::TreeModelColumn<Glib::ustring> table;
Gtk::TreeModelColumn<Glib::ustring> type;
Gtk::TreeModelColumn<Glib::ustring> possible_keys;
Gtk::TreeModelColumn<Glib::ustring> key;
Gtk::TreeModelColumn<Glib::ustring> key_len;
Gtk::TreeModelColumn<Glib::ustring> ref;
Gtk::TreeModelColumn<Glib::ustring> rows;
Gtk::TreeModelColumn<Glib::ustring> extra;
} _exp_columns;
class PopupTreeView : public Gtk::TreeView {
virtual bool on_button_press_event(GdkEventButton *ev);
Gtk::Menu *_popup;
sigc::signal0<void> _signal_will_popup;
public:
PopupTreeView(Gtk::Menu *popup) : Gtk::TreeView(), _popup(popup) {};
sigc::signal0<void> signal_will_popup() { return _signal_will_popup; };
};
enum FieldAction {
FieldLoad,
FieldSave,
FieldCopy,
FieldClear,
FieldEdit,
FieldView
};
ModelColumns *_columns;
Gtk::ScrolledWindow _scroll;
PopupTreeView *_tree;
Gtk::EventBox _ebox;
Gtk::HBox _hbox;
Gtk::Label _status_label;
Gtk::VSeparator _sep1;
Gtk::Button _edit_btn;
Gtk::VSeparator _sep1a;
Gtk::Button _apply_btn;
Gtk::VSeparator _sep1b;
Gtk::VSeparator _sep2;
Gtk::Button _first_btn;
Gtk::VSeparator _sep2a;
Gtk::Button _last_btn;
Gtk::VSeparator _sep2b;
Gtk::Button _search_btn;
Gtk::ScrolledWindow _msgscroll;
Gtk::TreeView _msgtree;
Glib::RefPtr<Gtk::ListStore> _msgstore;
Gtk::Window *_explain_window;
Glib::RefPtr<MGResultSetModel> _model;
Gtk::Menu _edit_menu;
MYX_RESULTSET *_result;
MQQueryParameters *_params;
bool _current_query_cancelled;
Glib::ustring _current_query;
struct timeval _current_query_start;
MQQueryDispatcher *_dispatcher;
MQHistory *_history_list;
std::list<std::string> _history;
int _history_index;
QueryStartedSignal _query_started_signal;
QueryFinishedSignal _query_finished_signal;
QueryMoreDataSignal _query_more_data_signal;
ActivateSignal _activate_signal;
RowChangedSignal _row_changed_signal;
sigc::signal0<void> _editable_change_signal;
bool _editing;
bool _is_busy;
bool _compact_mode;
bool _active;
bool get_selected_field(Gtk::TreePath &path, int &column);
void editor_save(MGBlobEditor *editor);
virtual void blob_edit(CellRendererBlob *cell, Gtk::Widget *widget, const Glib::ustring &path, int column);
virtual void blob_save(CellRendererBlob *cell, Gtk::Widget *widget, const Glib::ustring &path, int column);
virtual void blob_load(CellRendererBlob *cell, Gtk::Widget *widget, const Glib::ustring &path, int column);
virtual void blob_clear(CellRendererBlob *cell, Gtk::Widget *widget, const Glib::ustring &path, int column);
virtual void blob_view(CellRendererBlob *cell, Gtk::Widget *widget, const Glib::ustring &path, int column);
void blob_data_edited(const Glib::ustring& path, gpointer data, gsize size, int column);
void string_data_edited(const Glib::ustring& path, const Glib::ustring& new_text, int column);
void display_result(MYX_RESULTSET *result);
void display_errors(MYX_MYSQL_ERROR_MSGS *errors);
void query_finished(MYX_RESULTSET *result,MYX_MYSQL_ERROR_MSGS*warnings);
bool query_progress(MYX_RESULTSET *result, unsigned long count,
unsigned long prev_count);
void query_error(MYX_RESULTSET *result, MYX_MYSQL_ERROR_MSGS*errors, MYX_LIB_ERROR merror);
void query_fetch_more(MYSQL *mysql);
void save_finished(MYX_RS_ACTION_ERRORS *errors);
void update_menu();
void edit_start();
void edit_apply();
void go_first();
void go_last();
std::vector<bool> get_search_column_list(const Glib::ustring &column_list);
void selected_row();
void selected_error();
void add_history_entry(const Glib::ustring &query);
void update_edit_button_sensitivity();
void set_sensitive(bool flag);
bool show_menu(GdkEventButton *ev);
bool editbar_clicked(GdkEventButton *ev);
bool focused(GdkEventFocus *ev);
void append_error(int num, const Glib::ustring &msg,
Glib::RefPtr<Gdk::Pixbuf> icon= Glib::RefPtr<Gdk::Pixbuf>(),
int row=-1);
void save_cell_change(MGBlobEditor *editor,
unsigned int column);
void add_row_mi();
void delete_row_mi();
void undo_row_mi();
bool tree_key_released(GdkEventKey *event);
void column_action_mi(FieldAction action);
public:
MQResultSetView(MQQueryDispatcher *disp, MQHistory *history,
MQGlobalQueryParameters *params);
~MQResultSetView();
void set_show_editbar(bool flag);
void redisplay();
void execute_query(const Glib::ustring &query,
bool refresh= false);
void fetch_more(MYSQL *mysql);
void cancel_query();
bool explain_query();
bool explain_shown() { return _explain_window != 0; };
void hide_explain();
bool hide_explain_d(GdkEventAny *ev);
Glib::ustring get_shown_query() { return _result ? _current_query : ""; };
Glib::ustring go_history_next();
Glib::ustring go_history_back();
int get_history_index();
bool is_busy() { return _is_busy; };
bool get_active();
void set_active(bool flag);
void set_compact_editbar(bool flag);
void set_search_func(const sigc::slot1<void,MQResultSetView*> &slot);
MYX_RESULTSET *get_resultset() { return _result; };
MYX_RS_ROW *get_selected_row();
Glib::RefPtr<MGResultSetModel> get_model() { return _model; };
void copy_row_to_clipboard();
void copy_row_names_to_clipboard();
bool find_next(const Glib::ustring &str, const Glib::ustring &columns);
bool find_previous(const Glib::ustring &str, const Glib::ustring &columns);
bool find_next_diff();
bool find_previous_diff();
bool is_editable();
Gtk::TreePath get_selected_row_path();
void set_selected_row_path(const Gtk::TreePath &path);
std::list<std::string> get_history() const { return _history; };
QueryStartedSignal signal_query_started() { return _query_started_signal; };
QueryFinishedSignal signal_query_finished() { return _query_finished_signal; };
QueryMoreDataSignal signal_more_data() { return _query_more_data_signal; };
ActivateSignal signal_activate() { return _activate_signal; };
RowChangedSignal signal_row_changed() { return _row_changed_signal; };
sigc::signal0<void> signal_editable_changed() { return _editable_change_signal; };
Gtk::ScrolledWindow *get_scrollwin() { return &_scroll; };
MQQueryParameters *get_parameters() { return _params; };
Gtk::Menu *get_menu() { return &_edit_menu; };
bool dispose_if_no_result;
};
#endif /* _MQRESULTSETVIEW_H_ */
|