| 1 |
/* AbiWord |
| 2 |
* Copyright (C) 2000-2002 AbiSource, Inc. |
| 3 |
* |
| 4 |
* This program is free software; you can redistribute it and/or |
| 5 |
* modify it under the terms of the GNU General Public License |
| 6 |
* as published by the Free Software Foundation; either version 2 |
| 7 |
* of the License, or (at your option) any later version. |
| 8 |
* |
| 9 |
* This program is distributed in the hope that it will be useful, |
| 10 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 |
* GNU General Public License for more details. |
| 13 |
* |
| 14 |
* You should have received a copy of the GNU General Public License |
| 15 |
* along with this program; if not, write to the Free Software |
| 16 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
| 17 |
* 02110-1301 USA. |
| 18 |
*/ |
| 19 |
|
| 20 |
#include <stdlib.h> |
| 21 |
|
| 22 |
#include "ut_string.h" |
| 23 |
#include "ut_assert.h" |
| 24 |
#include "ut_debugmsg.h" |
| 25 |
|
| 26 |
#include "xap_UnixDialogHelper.h" |
| 27 |
#include "xap_Gtk2Compat.h" |
| 28 |
|
| 29 |
#include "xap_App.h" |
| 30 |
#include "xap_UnixApp.h" |
| 31 |
#include "xap_Frame.h" |
| 32 |
|
| 33 |
#include "xap_Strings.h" |
| 34 |
#include "xap_Dialog_Id.h" |
| 35 |
#include "xap_UnixDlg_Password.h" |
| 36 |
|
| 37 |
void XAP_UnixDialog_Password::event_OK () |
| 38 |
{ |
| 39 |
const char * txt = gtk_entry_get_text (GTK_ENTRY(mTextEntry)); |
| 40 |
if (txt && strlen(txt)) { |
| 41 |
setPassword (txt); |
| 42 |
setAnswer(XAP_Dialog_Password::a_OK); |
| 43 |
} else { |
| 44 |
setAnswer(XAP_Dialog_Password::a_Cancel); |
| 45 |
} |
| 46 |
} |
| 47 |
|
| 48 |
void XAP_UnixDialog_Password::event_Return() |
| 49 |
{ |
| 50 |
gtk_dialog_response ( GTK_DIALOG ( mMainWindow ), GTK_RESPONSE_OK ) ; |
| 51 |
} |
| 52 |
|
| 53 |
void XAP_UnixDialog_Password::event_Cancel () |
| 54 |
{ |
| 55 |
setAnswer(XAP_Dialog_Password::a_Cancel); |
| 56 |
} |
| 57 |
|
| 58 |
XAP_Dialog * XAP_UnixDialog_Password::static_constructor(XAP_DialogFactory * pFactory, |
| 59 |
XAP_Dialog_Id id) |
| 60 |
{ |
| 61 |
return new XAP_UnixDialog_Password(pFactory,id); |
| 62 |
} |
| 63 |
|
| 64 |
XAP_UnixDialog_Password::XAP_UnixDialog_Password(XAP_DialogFactory * pDlgFactory, |
| 65 |
XAP_Dialog_Id id) |
| 66 |
: XAP_Dialog_Password(pDlgFactory,id) |
| 67 |
{ |
| 68 |
} |
| 69 |
|
| 70 |
XAP_UnixDialog_Password::~XAP_UnixDialog_Password(void) |
| 71 |
{ |
| 72 |
} |
| 73 |
|
| 74 |
void XAP_UnixDialog_Password::runModal(XAP_Frame * pFrame) |
| 75 |
{ |
| 76 |
GtkWidget * cf = _constructWindow(); |
| 77 |
UT_return_if_fail(cf); |
| 78 |
|
| 79 |
switch ( abiRunModalDialog ( GTK_DIALOG(cf), pFrame, this, GTK_RESPONSE_OK, false ) ) |
| 80 |
{ |
| 81 |
case GTK_RESPONSE_OK: |
| 82 |
event_OK(); break; |
| 83 |
default: |
| 84 |
event_Cancel(); break; |
| 85 |
} |
| 86 |
|
| 87 |
XAP_gdk_keyboard_ungrab(GDK_CURRENT_TIME); |
| 88 |
|
| 89 |
abiDestroyWidget(cf); |
| 90 |
} |
| 91 |
|
| 92 |
GtkWidget * XAP_UnixDialog_Password::_constructWindow () |
| 93 |
{ |
| 94 |
const XAP_StringSet * pSS = m_pApp->getStringSet(); |
| 95 |
|
| 96 |
// load the dialog from the UI file |
| 97 |
#if GTK_CHECK_VERSION(3,0,0) |
| 98 |
GtkBuilder* builder = newDialogBuilder("xap_UnixDlg_Password.ui"); |
| 99 |
#else |
| 100 |
GtkBuilder* builder = newDialogBuilder("xap_UnixDlg_Password-2.ui"); |
| 101 |
#endif |
| 102 |
|
| 103 |
// Update our member variables with the important widgets that |
| 104 |
// might need to be queried or altered later |
| 105 |
mMainWindow = GTK_WIDGET(gtk_builder_get_object(builder, "xap_UnixDlg_Password")); |
| 106 |
mTextEntry = GTK_WIDGET(gtk_builder_get_object(builder, "enPassword")); |
| 107 |
|
| 108 |
std::string s; |
| 109 |
pSS->getValueUTF8(XAP_STRING_ID_DLG_Password_Title,s); |
| 110 |
gtk_window_set_title (GTK_WINDOW(mMainWindow), s.c_str()); |
| 111 |
|
| 112 |
/* localize labels */ |
| 113 |
localizeLabel (GTK_WIDGET(gtk_builder_get_object(builder, "lbPassword")), pSS, XAP_STRING_ID_DLG_Password_Password); |
| 114 |
|
| 115 |
g_signal_connect (G_OBJECT(mTextEntry), "activate", |
| 116 |
G_CALLBACK(s_return_hit), |
| 117 |
static_cast<gpointer>(this)); |
| 118 |
|
| 119 |
gtk_widget_grab_focus(mTextEntry); |
| 120 |
|
| 121 |
g_object_unref(G_OBJECT(builder)); |
| 122 |
|
| 123 |
return mMainWindow; |
| 124 |
} |