made the passwd dialog call Qt-independent (thanks to notifyBase)

git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@1793 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
csoler 2009-11-05 19:38:10 +00:00
parent 9df3b567e7
commit 7c1288411a
6 changed files with 25 additions and 10 deletions

View File

@ -54,9 +54,9 @@
*/ */
#include "authgpg.h" #include "authgpg.h"
#include <rsiface/rsiface.h>
#include <iostream> #include <iostream>
#include <sstream> #include <sstream>
#include <QtGui>
/* Turn a set of parameters into a string */ /* Turn a set of parameters into a string */
static std::string setKeyPairParams(bool useRsa, unsigned int blen, static std::string setKeyPairParams(bool useRsa, unsigned int blen,
@ -100,9 +100,11 @@ gpgcert::~gpgcert()
gpg_error_t pgp_pwd_callback(void *hook, const char *uid_hint, const char *passphrase_info, int prev_was_bad, int fd) gpg_error_t pgp_pwd_callback(void *hook, const char *uid_hint, const char *passphrase_info, int prev_was_bad, int fd)
{ {
QString text = QInputDialog::getText(NULL, "GPG key passphrase", std::string text = rsicontrol->getNotify().askForPassword("GPG key passphrase","GPG key passphrase") ;
"GPG key passphrase", QLineEdit::Password,
NULL, NULL); // QString text = QInputDialog::getText(NULL, "GPG key passphrase",
// "GPG key passphrase", QLineEdit::Password,
// NULL, NULL);
if (prev_was_bad) if (prev_was_bad)
@ -111,12 +113,12 @@ gpg_error_t pgp_pwd_callback(void *hook, const char *uid_hint, const char *passp
fprintf(stderr, "pgp_pwd_callback() Set Password\n"); fprintf(stderr, "pgp_pwd_callback() Set Password\n");
#ifndef WINDOWS_SYS #ifndef WINDOWS_SYS
write(fd, text.toStdString().c_str(), text.length()); write(fd, text.c_str(), text.size());
write(fd, "\n", 1); /* needs a new line? */ write(fd, "\n", 1); /* needs a new line? */
#else #else
DWORD written = 0; DWORD written = 0;
HANDLE winFd = (HANDLE) fd; HANDLE winFd = (HANDLE) fd;
WriteFile(winFd, text.toStdString().c_str(), text.length(), &written, NULL); WriteFile(winFd, text.c_str(), text.size(), &written, NULL);
WriteFile(winFd, "\n", 1, &written, NULL); WriteFile(winFd, "\n", 1, &written, NULL);
#endif #endif

View File

@ -207,6 +207,8 @@ class NotifyBase
virtual void notifyPeerHasNewAvatar(std::string peer_id) { (void)peer_id; } virtual void notifyPeerHasNewAvatar(std::string peer_id) { (void)peer_id; }
virtual void notifyOwnAvatarChanged() {} virtual void notifyOwnAvatarChanged() {}
virtual void notifyOwnStatusMessageChanged() {} virtual void notifyOwnStatusMessageChanged() {}
virtual std::string askForPassword(const std::string& window_title,const std::string& text) {}
}; };
const int NOTIFY_LIST_NEIGHBOURS = 1; const int NOTIFY_LIST_NEIGHBOURS = 1;

View File

@ -48,6 +48,10 @@ int main(int argc, char *argv[])
rsiface = NULL; rsiface = NULL;
NotifyQt *notify = new NotifyQt();
createRsIface(*notify);
createRsControl(*rsiface, *notify);
/* RetroShare Core Objects */ /* RetroShare Core Objects */
RsInit::InitRsConfig(); RsInit::InitRsConfig();
bool okStart = RsInit::InitRetroShare(argc, argv); bool okStart = RsInit::InitRetroShare(argc, argv);
@ -118,10 +122,6 @@ int main(int argc, char *argv[])
RsInit::LoadCertificates(false); RsInit::LoadCertificates(false);
} }
NotifyQt *notify = new NotifyQt();
createRsIface(*notify);
createRsControl(*rsiface, *notify);
rsicontrol->StartupRetroShare(); rsicontrol->StartupRetroShare();
MainWindow *w = new MainWindow; MainWindow *w = new MainWindow;
@ -145,6 +145,7 @@ int main(int argc, char *argv[])
QObject::connect(notify,SIGNAL(configChanged()) ,w->messagesDialog ,SLOT(displayConfig() )) ; QObject::connect(notify,SIGNAL(configChanged()) ,w->messagesDialog ,SLOT(displayConfig() )) ;
QObject::connect(notify,SIGNAL(chatStatusChanged(const QString&,const QString&,bool)),w->peersDialog,SLOT(updatePeerStatusString(const QString&,const QString&,bool))); QObject::connect(notify,SIGNAL(chatStatusChanged(const QString&,const QString&,bool)),w->peersDialog,SLOT(updatePeerStatusString(const QString&,const QString&,bool)));
QObject::connect(notify,SIGNAL(peerHasNewCustomStateString(const QString&)),w->peersDialog,SLOT(updatePeersCustomStateString(const QString&)));
QObject::connect(notify,SIGNAL(peerHasNewAvatar(const QString&)),w->peersDialog,SLOT(updatePeersAvatar(const QString&))); QObject::connect(notify,SIGNAL(peerHasNewAvatar(const QString&)),w->peersDialog,SLOT(updatePeersAvatar(const QString&)));
QObject::connect(notify,SIGNAL(ownAvatarChanged()),w->peersDialog,SLOT(updateAvatar())); QObject::connect(notify,SIGNAL(ownAvatarChanged()),w->peersDialog,SLOT(updateAvatar()));
QObject::connect(notify,SIGNAL(ownStatusMessageChanged()),w->peersDialog,SLOT(loadmypersonalstatus())); QObject::connect(notify,SIGNAL(ownStatusMessageChanged()),w->peersDialog,SLOT(loadmypersonalstatus()));

View File

@ -44,6 +44,13 @@ void NotifyQt::notifyOwnAvatarChanged()
emit ownAvatarChanged() ; emit ownAvatarChanged() ;
} }
std::string NotifyQt::askForPassword(const std::string& window_title,const std::string& text)
{
return QInputDialog::getText(NULL, QString::fromStdString(window_title),
QString::fromStdString(text), QLineEdit::Password,
NULL, NULL).toStdString();
}
void NotifyQt::notifyOwnStatusMessageChanged() void NotifyQt::notifyOwnStatusMessageChanged()
{ {
std::cerr << "Notifyqt:: notified that own avatar changed" << std::endl ; std::cerr << "Notifyqt:: notified that own avatar changed" << std::endl ;

View File

@ -40,6 +40,7 @@ class NotifyQt: public QObject, public NotifyBase
virtual void notifyPeerHasNewAvatar(std::string peer_id) ; virtual void notifyPeerHasNewAvatar(std::string peer_id) ;
virtual void notifyOwnAvatarChanged() ; virtual void notifyOwnAvatarChanged() ;
virtual void notifyOwnStatusMessageChanged() ; virtual void notifyOwnStatusMessageChanged() ;
virtual std::string askForPassword(const std::string& window_title,const std::string& text) ;
signals: signals:
// It's beneficial to send info to the GUI using signals, because signals are thread-safe // It's beneficial to send info to the GUI using signals, because signals are thread-safe

View File

@ -207,6 +207,8 @@ class NotifyBase
virtual void notifyPeerHasNewAvatar(std::string peer_id) { (void)peer_id; } virtual void notifyPeerHasNewAvatar(std::string peer_id) { (void)peer_id; }
virtual void notifyOwnAvatarChanged() {} virtual void notifyOwnAvatarChanged() {}
virtual void notifyOwnStatusMessageChanged() {} virtual void notifyOwnStatusMessageChanged() {}
virtual std::string askForPassword(const std::string& window_title,const std::string& text) {}
}; };
const int NOTIFY_LIST_NEIGHBOURS = 1; const int NOTIFY_LIST_NEIGHBOURS = 1;