File: MGCharsetPickDialog.cc

package info (click to toggle)
mysql-query-browser 1.1.6-1sarge0
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 36,320 kB
  • ctags: 24,680
  • sloc: pascal: 203,479; xml: 136,561; ansic: 47,502; cpp: 28,926; sh: 12,433; objc: 4,823; java: 1,849; php: 1,485; python: 1,225; sql: 1,128; makefile: 872
file content (125 lines) | stat: -rw-r--r-- 4,274 bytes parent folder | download
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
/* 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 */

#include "MGCharsetPickDialog.h"
#include <gtkmm/stock.h>
#include "myg_gtkutils.h"
#include "mygpriv.h"

static void dummy()
{
}


MGCharsetPickDialog::MGCharsetPickDialog()
  : Gtk::Dialog(_("Select Encoding of File"), true, true),
   _hbox(false, 12), _detect(_("Auto Detect"))
{
  _message.set_label(_("Please pick the correct character set encoding for the file."));
  
  get_vbox()->set_spacing(12);
  get_vbox()->pack_start(_message, false, false);
  get_vbox()->pack_start(_hbox, false, false);
  _hbox.pack_start(_option, true, true);
  _hbox.pack_start(_detect, false, false);
  _hbox.set_border_width(8);
  
  _detect.signal_clicked().connect(SigC::slot(*this,&MGCharsetPickDialog::autodetect));
  
  Gtk::Menu *menu= Gtk::manage(new Gtk::Menu());
  _option.set_menu(*menu);
  myg_menu_add(*menu, "utf8", SigC::slot(dummy), "utf8");
  myg_menu_add(*menu, "latin1", SigC::slot(dummy), "latin1");
  myg_menu_add(*menu, "sjis", SigC::slot(dummy), "sjis");
  myg_menu_add(*menu, "EUC-JP", SigC::slot(dummy), "EUC-JP");
  myg_menu_add(*menu, "big5", SigC::slot(dummy), "big5");
  myg_menu_add(*menu, "cp850", SigC::slot(dummy), "cp850");
  myg_menu_add(*menu, "cp866", SigC::slot(dummy), "cp866");
  myg_menu_add(*menu, "latin2", SigC::slot(dummy), "latin2");
  myg_menu_add(*menu, "latin5", SigC::slot(dummy), "latin5");
  myg_menu_add(*menu, "latin7", SigC::slot(dummy), "latin7");
  myg_menu_add(*menu, "hebrew", SigC::slot(dummy), "hebrew");
  myg_menu_add(*menu, "tis620", SigC::slot(dummy), "tis620");
  myg_menu_add(*menu, "euckr", SigC::slot(dummy), "euckr");
  myg_menu_add(*menu, "gb2312", SigC::slot(dummy), "gb2312");
  myg_menu_add(*menu, "greek", SigC::slot(dummy), "greek");
  myg_menu_add(*menu, "cp1250", SigC::slot(dummy), "cp1250");
  myg_menu_add(*menu, "gbk", SigC::slot(dummy), "gbk");
  myg_menu_add(*menu, "macroman", SigC::slot(dummy), "macroman");
  myg_menu_add(*menu, "cp1251", SigC::slot(dummy), "cp1251");
  myg_menu_add(*menu, "cp1256", SigC::slot(dummy), "cp1256");
  myg_menu_add(*menu, "cp1257", SigC::slot(dummy), "cp1257");
  myg_menu_add(*menu, "HP-ROMAN8", SigC::slot(dummy), "HP-ROMAN8");
  myg_menu_add(*menu, "KOI8-R", SigC::slot(dummy), "KOI8-R");
  myg_menu_add(*menu, "US-ASCII", SigC::slot(dummy), "US-ASCII");
  myg_menu_add(*menu, "KOI8-U", SigC::slot(dummy), "KOI8-U");
  myg_menu_add(*menu, "ARMSCII-8", SigC::slot(dummy), "ARMSCII-8");
  myg_menu_add(*menu, "UCS-2", SigC::slot(dummy), "UCS-2");
  myg_menu_add(*menu, "MACCENTRALEUROPE", SigC::slot(dummy), "MACCENTRALEUROPE");

  _option.set_history(0);
  
  add_button(Gtk::Stock::CANCEL, 0);
  add_button(Gtk::Stock::OK, 1);

  get_vbox()->show_all();
  
  _detect.hide();
}


void MGCharsetPickDialog::autodetect()
{
  if (_detect_func)
  {
    Glib::ustring chs;
    int index;
    
    if (_detect_func(chs))
    {      
      index= myg_menu_get_index_with_id(*_option.get_menu(), chs);
      if (index < 0)
        myg_show_info(_("Could not detect encoding of file."));
      else
        _option.set_history(index);
    }
    else
      myg_show_info(_("Could not detect encoding of file."));
  }
}


void MGCharsetPickDialog::set_detect_function(const SigC::Slot1<bool,Glib::ustring&> &func)
{
  _detect_func= func;
  _detect.show();
}

    
Glib::ustring MGCharsetPickDialog::show(const Glib::ustring &message)
{  
  _message.set_text(message);

  if (run() == 1)
  {
    Glib::ustring chs;
    
    chs= myg_menu_get_id_at_index(*_option.get_menu(), _option.get_history());

    return chs;
  }
  return "";
}