home *** CD-ROM | disk | FTP | other *** search
/ Dream 49 / Amiga_Dream_49.iso / beos / utils / skey-1.000 / SKey-1.4.3 / Source / Sources / SKeyApp.cc < prev    next >
C/C++ Source or Header  |  1997-12-03  |  2KB  |  101 lines

  1. #include "SKeyMessage.h"
  2. #include "SKeyApp.h"
  3. #include "SKeyWindow.h"
  4. #include "Preferences.h"
  5.  
  6. #include <Application.h>
  7. #include <storage/Resources.h>
  8.  
  9. #define ABOUT_MESS "S/Key One Time Password Generator\n\
  10. Copyright" B_UTF8_COPYRIGHT " 1997 Brian Cully <shmit@kublai.com>\n\n\
  11. This program comes with ABSOLUTELY NO WARRANTY. This is free software, \
  12. you are welcome to redistribute it and modify it under the terms of the \
  13. conditions of the GNU General Public License.\n\n\
  14. The RSA Data Security, Inc. MD4 Message-Digest Algorithm and \
  15. RSA Data Security, Inc. MD5 Message-Digest Algorithm are \
  16. Copyright " B_UTF8_COPYRIGHT " 1990-1992 RSA Data Security."
  17.  
  18. SKeyApp::SKeyApp()
  19.         : BApplication("application/x-kublai-skey")
  20. {
  21.     prefs = new Preferences("x-kublai-skey");
  22.     settings = new PreferenceSet(*prefs, "settings", true);
  23.  
  24.     if (prefs->InitCheck()) {
  25.         prefs = NULL;
  26.         settings = NULL;
  27.     }
  28.     if (settings->InitCheck()) {
  29.         settings = NULL;
  30.     }
  31. }
  32.  
  33. void SKeyApp::AboutRequested()
  34. {
  35.     BAlert *about_box = new BAlert("", ABOUT_MESS, "OK", NULL, NULL, B_WIDTH_AS_USUAL,
  36.                                    B_INFO_ALERT);
  37.  
  38.     if (about_box)
  39.         about_box->Go();
  40. }
  41.  
  42. void SKeyApp::MessageReceived(BMessage *msg)
  43. {
  44.     switch (msg->what) {
  45.     case SKEY_PREFS_MSG:
  46.         BRect pos;
  47.         bool md;
  48.  
  49.         // TODO: Make sure this data exists.
  50.         msg->FindRect("position", &pos);
  51.         msg->FindBool("md", &md);
  52.         WritePrefs(pos, md);
  53.         break;
  54.     default:
  55.         BApplication::MessageReceived(msg);
  56.     }
  57. }
  58.  
  59. bool SKeyApp::QuitRequested()
  60. {
  61.     return TRUE;
  62. }
  63.  
  64. void SKeyApp::ReadyToRun()
  65. {
  66.     app_info info; 
  67.     BRect win_pos;
  68.     bool md4;
  69.  
  70.     if (GetAppInfo(&info) != B_OK) {
  71.         BAlert *oops = new BAlert("", "Can't find myself!", "Argh", NULL,
  72.                                    NULL, B_WIDTH_AS_USUAL, B_STOP_ALERT);
  73.                     
  74.         oops->Go();
  75.         return;
  76.     }
  77.  
  78.     /* Scarf preferences. */
  79.     const void *data;
  80.     size_t size;
  81.     uint32 type;
  82.  
  83.     if (settings->GetData(SKEY_WINPOS_RES, data, size, type) || type != B_RECT_TYPE)
  84.         win_pos.Set(100, 100, 500, 210);
  85.     else
  86.         memcpy(&win_pos, data, size);
  87.  
  88.     if (settings->GetData(SKEY_MD_RES, data, size, type) || type != B_BOOL_TYPE)
  89.         md4 = true;
  90.     else
  91.         memcpy(&md4, data, size);
  92.  
  93.     SKeyWindow *win = new SKeyWindow(win_pos, md4);
  94. }
  95.  
  96. void SKeyApp::WritePrefs(BRect frame, bool md4)
  97. {
  98.     settings->SetData(SKEY_WINPOS_RES, &frame, sizeof(frame), B_RECT_TYPE);
  99.     settings->SetData(SKEY_MD_RES, &md4, sizeof(md4), B_BOOL_TYPE);
  100.     settings->Save();
  101. }