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
|
/* $Id: kbdselmenu-kde.cpp,v 1.2 1999/07/30 16:43:39 stano Exp $
KDE popup menu for keyboard selection
(C) 1999 Stanislav Meduna <stano@eunet.sk>
*/
#include <kbdselmenu-kde.h>
#include <qfont.h>
#include <kapp.h>
#include <xkbselx.h>
#include <stdio.h>
#include <libintl.h>
#define _(s) gettext(s)
KbdSelPopMenu::KbdSelPopMenu(QWidget *parent, const char *name)
: KPopupMenu(parent, name),
infos(0)
{
}
KbdSelPopMenu::~KbdSelPopMenu()
{
delete [] infos;
}
int KbdSelPopMenu::constructMenu()
{
int i;
int r;
setFont(QFont("Courier", 10, QFont::Normal));
setTitle(_("Select a keyboard"));
infos = new (sel_info_t *)[KPM_FirstItem + n_locale_maps];
if (! infos)
return -1;
r = open_db();
if (r < 0)
return -1;
for (i=0; i < n_locale_maps; i++)
{
char buf2[MAX_SHORTCUT_LEN+MAX_DESCRIPTION_LEN+16];
db_record_t rec;
int found;
int mi;
r = read_db_name(locale_maps[i].map_name, &rec, &found);
if (r < 0)
return -1;
if (! found)
{
fprintf(stderr, _("Map name %s not found - ignored\n"),
locale_maps[i].map_name);
continue;
}
sprintf(buf2, "%-8s %s",
locale_maps[i].shortcut,
*rec.descr ? rec.descr : locale_maps[i].map_name);
mi = insertItem(buf2);
infos[mi] = locale_maps + i;
}
close_db();
connect(this, SIGNAL(activated(int)), SLOT(setKbd(int)));
// Select first keyboard
setKbd(KPM_FirstItem);
}
void KbdSelPopMenu::setKbd(int idx)
{
int r;
// There are people that try to select the menu title :-)
if (idx < KPM_FirstItem)
return;
if (flag_debug)
fprintf(stderr, "Selected %s\n", infos[idx]->shortcut);
r = open_db();
if (r < 0)
return;
r = install_map(infos[idx]->map_name);
if (! r)
publish_current_sel(KApplication::getKApplication()->getDisplay(), infos[idx]);
close_db();
return;
}
|