1
/* main.cpp - Secure KDE dialog for PIN entry.
2
Copyright (C) 2002 Klar�lvdalens Datakonsult AB
3
Copyright (C) 2003 g10 Code GmbH
4
Written by Steffen Hansen <steffen@klaralvdalens-datakonsult.se>.
5
Modified by Marcus Brinkmann <marcus@g10code.de>.
7
This program is free software; you can redistribute it and/or
8
modify it under the terms of the GNU General Public License as
9
published by the Free Software Foundation; either version 2 of the
10
License, or (at your option) any later version.
12
This program is distributed in the hope that it will be useful, but
13
WITHOUT ANY WARRANTY; without even the implied warranty of
14
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15
General Public License for more details.
17
You should have received a copy of the GNU General Public License
18
along with this program; if not, write to the Free Software
19
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
29
#include <qapplication.h>
31
#include <qmessagebox.h>
32
#include "secqstring.h"
34
#include "pinentrydialog.h"
38
#ifdef FALLBACK_CURSES
39
#include <pinentry-curses.h>
42
/* Hack for creating a QWidget with a "foreign" window ID */
43
class ForeignWidget : public QWidget
46
ForeignWidget( WId wid ) : QWidget( 0 )
49
create( wid, false, false );
54
destroy( false, false );
59
qt_cmd_handler (pinentry_t pe)
63
int want_pass = !!pe->pin;
67
/* FIXME: Add parent window ID to pinentry and GTK. */
69
parent = new ForeignWidget (pe->parent_wid);
71
PinEntryDialog pinentry (parent, NULL, true, !!pe->quality_bar);
73
pinentry.setPinentryInfo (pe);
74
pinentry.setPrompt (QString::fromUtf8 (pe->prompt));
75
pinentry.setDescription (QString::fromUtf8 (pe->description));
76
/* If we reuse the same dialog window. */
78
pinentry.setText (SecQString::null);
82
pinentry.setOkText (QString::fromUtf8 (pe->ok));
84
pinentry.setCancelText (QString::fromUtf8 (pe->cancel));
86
pinentry.setError (QString::fromUtf8 (pe->error));
88
pinentry.setQualityBar (QString::fromUtf8 (pe->quality_bar));
89
if (pe->quality_bar_tt)
90
pinentry.setQualityBarTT (QString::fromUtf8 (pe->quality_bar_tt));
92
bool ret = pinentry.exec ();
96
char *pin = (char *) pinentry.text().utf8();
100
int len = strlen (pin);
103
pinentry_setbufferlen (pe, len + 1);
106
strcpy (pe->pin, pin);
116
bool ret = QMessageBox::information (parent, "", pe->description,
117
pe->ok ? pe->ok : "OK",
118
pe->cancel ? pe->cancel : "Cancel");
123
pinentry_cmd_handler_t pinentry_cmd_handler = qt_cmd_handler;
126
main (int argc, char *argv[])
128
pinentry_init ("pinentry-qt");
130
#ifdef FALLBACK_CURSES
131
if (!pinentry_have_display (argc, argv))
132
pinentry_cmd_handler = curses_cmd_handler;
136
/* Qt does only understand -display but not --display; thus we
137
are fixing that here. The code is pretty simply and may get
138
confused if an argument is called "--display". */
143
for (n=0,i=0; i < argc; i++)
144
n += strlen (argv[i])+1;
146
new_argv = (char**)calloc (argc+1, sizeof *new_argv);
148
*new_argv = (char*)malloc (n);
149
if (!new_argv || !*new_argv)
151
fprintf (stderr, "pinentry-qt: can't fixup argument list: %s\n",
156
for (done=0,p=*new_argv,i=0; i < argc; i++)
157
if (!done && !strcmp (argv[i], "--display"))
159
new_argv[i] = "-display";
164
new_argv[i] = strcpy (p, argv[i]);
165
p += strlen (argv[i]) + 1;
168
/* We use a modal dialog window, so we don't need the application
171
new QApplication (i, new_argv);
175
/* Consumes all arguments. */
176
if (pinentry_parse_opts (argc, argv))
178
printf ("pinentry-qt (pinentry) " VERSION "\n");
182
if (pinentry_loop ())