File: MQBookmarks.h

package info (click to toggle)
mysql-gui-tools 5.0r14%2BopenSUSE-2.1
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 116,956 kB
  • ctags: 48,715
  • sloc: sql: 341,918; pascal: 276,698; ansic: 91,020; cpp: 90,451; objc: 33,236; sh: 29,481; yacc: 10,756; xml: 10,589; java: 10,079; php: 2,806; python: 2,092; makefile: 1,783; perl: 4
file content (134 lines) | stat: -rw-r--r-- 4,056 bytes parent folder | download | duplicates (3)
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
/* 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 _MQBOOKMARKS_H_
#define _MQBOOKMARKS_H_

#include <gtkmm/tooltips.h>
#include <gtkmm/menu.h>
#include "myx_qb_public_interface.h"

class MGGladeXML;
class MQNewBookmarkDialog;
class MQBookmarkBrowser;

class MQBookmarks : public Glib::ObjectBase {
  public:
    class Bookmark {
      public:
        Glib::ustring name;
        virtual ~Bookmark() {};
        virtual bool is_group()= 0;
    };
    class BookmarkGroup : public Bookmark {
      public:
        std::list<Bookmark*> items;
        virtual ~BookmarkGroup() 
        {
          for (std::list<Bookmark*>::iterator i=items.begin(); i!=items.end(); ++i)
            delete *i;
        }

        virtual bool is_group() { return true; };
        
        BookmarkGroup *find_group(const Glib::ustring &group)
        {
          if (name == group)
            return this;

          for (std::list<Bookmark*>::const_iterator iter= items.begin();
               iter != items.end(); ++iter)
          {
            if (((BookmarkGroup*)*iter)->is_group())
            {
              BookmarkGroup *g= ((BookmarkGroup*)*iter)->find_group(group);
              if (g)
                return g;
            }
          }
          return 0;
        }
    };
    class BookmarkItem : public Bookmark {
      public:
        Glib::ustring query;

        Glib::ustring catalog;
        Glib::ustring schema;

        unsigned int access_count;
        time_t ctime;
        time_t mtime;
        time_t atime;

        void touch() { time(&atime); };
        virtual bool is_group() { return false; };
    };

    typedef sigc::slot1<void,BookmarkItem*> OpenBookmarkSlot;
    typedef sigc::signal0<void> BookmarksChangedSignal;

  protected:
    MGGladeXML *_addxml;

    BookmarkGroup *_root_group;

    MQNewBookmarkDialog *_add_dialog;
    
    MQBookmarkBrowser *_browser;
    
    Gtk::Tooltips _tips;

    BookmarksChangedSignal _signal_changed;

    std::list<Glib::ustring> get_bookmark_folder_list();

    BookmarkGroup *load_group(MYX_BOOKMARK_GROUP *group);
    BookmarkItem *load_item(MYX_BOOKMARK *group);

    void store_group(BookmarkGroup *bgroup, MYX_BOOKMARK_GROUP *group);
    void store_item(BookmarkItem *item, MYX_BOOKMARK *bmk);
    void load();
    
    void add_bookmark_group_to_menu(Gtk::Menu *menu, BookmarkGroup *group,
                                    const OpenBookmarkSlot &slot);
  public:
    MQBookmarks(MGGladeXML *add_xml);
    virtual ~MQBookmarks();

    void save();

    void update_bookmark_menu(Gtk::Menu *menu, int index,
                              const OpenBookmarkSlot &slot);

    void interactive_add(const Glib::ustring &catalog,
                         const Glib::ustring &schema,
                         const Glib::ustring &query);
    
    BookmarkGroup *get_bookmarks() { return _root_group; };
    
    MQBookmarkBrowser *get_browser() { return _browser; };

    BookmarkGroup *create_group(BookmarkGroup *group, const Glib::ustring &name);
    bool delete_item(Bookmark *bm, BookmarkGroup *group= 0);

    void bookmarks_changed();
    
    BookmarksChangedSignal signal_changed() { return _signal_changed; };
};


#endif /* _MQBOOKMARKS_H_ */