1 /* 2 * Copyright 2002-2011, Haiku. All rights reserved. 3 * Distributed under the terms of the MIT License. 4 * 5 * Authors: 6 * Andrew McCall <mccall@digitalparadise.co.uk> 7 * Mike Berg <mike@berg-net.us> 8 * Julun <host.haiku@gmx.de> 9 * Hamish Morrison <hamish@lavabit.com> 10 */ 11 12 13 #include "Time.h" 14 15 #include <locale.h> 16 #include <stdio.h> 17 #include <unistd.h> 18 19 #include <Alert.h> 20 #include <Catalog.h> 21 #include <LocaleRoster.h> 22 23 #include "NetworkTimeView.h" 24 #include "TimeMessages.h" 25 #include "TimeWindow.h" 26 27 28 #undef B_TRANSLATION_CONTEXT 29 #define B_TRANSLATION_CONTEXT "Time" 30 31 32 const char* kAppSignature = "application/x-vnd.Haiku-Time"; 33 34 35 TimeApplication::TimeApplication() 36 : 37 BApplication(kAppSignature), 38 fWindow(NULL) 39 { 40 fWindow = new TTimeWindow(); 41 } 42 43 44 TimeApplication::~TimeApplication() 45 { 46 } 47 48 49 void 50 TimeApplication::ReadyToRun() 51 { 52 fWindow->Show(); 53 } 54 55 56 void 57 TimeApplication::AboutRequested() 58 { 59 BAlert* alert = new BAlert(B_TRANSLATE("about"), 60 B_TRANSLATE( 61 "Time & Date, written by:\n\n\tAndrew Edward McCall\n\tMike Berg\n\t" 62 "Julun\n\tPhilippe Saint-Pierre\n\nCopyright 2004-2012, Haiku."), 63 B_TRANSLATE("OK")); 64 alert->SetFlags(alert->Flags() | B_CLOSE_ON_ESCAPE); 65 alert->Go(); 66 } 67 68 69 void 70 TimeApplication::MessageReceived(BMessage* message) 71 { 72 switch (message->what) { 73 case kSelectClockTab: 74 case kShowHideTime: 75 case B_LOCALE_CHANGED: 76 fWindow->PostMessage(message); 77 break; 78 79 default: 80 BApplication::MessageReceived(message); 81 break; 82 } 83 } 84 85 86 int 87 main(int argc, char** argv) 88 { 89 if (argc > 1) { 90 if (strcmp(argv[1], "--update") != 0) 91 return 0; 92 93 Settings settings; 94 const char* errorString = NULL; 95 int32 errorCode = 0; 96 if (update_time(settings, &errorString, &errorCode) == B_OK) { 97 printf("Synchronization successful\n"); 98 } else if (errorCode != 0) { 99 printf("The following error occured " 100 "while synchronizing:\n%s: %s\n", 101 errorString, strerror(errorCode)); 102 } else { 103 printf("The following error occured while synchronizing:\n%s\n", 104 errorString); 105 } 106 } else { 107 setlocale(LC_ALL, ""); 108 109 TimeApplication app; 110 setuid(0); 111 app.Run(); 112 } 113 114 return 0; 115 } 116 117