diff --git a/src/apps/autoraise/AutoRaiseApp.cpp b/src/apps/autoraise/AutoRaiseApp.cpp index 3cf84459f2..c14d18e0ef 100644 --- a/src/apps/autoraise/AutoRaiseApp.cpp +++ b/src/apps/autoraise/AutoRaiseApp.cpp @@ -15,16 +15,6 @@ AutoRaiseApp::AutoRaiseApp() removeFromDeskbar(NULL); fPersist = true; fDone = false; - - //since the tray item shows an icon, and the class TrayView needs to be - //able to know the location of the executing binary, we write into the - //settings file this critical information when the app is fired up - app_info info; - be_app->GetAppInfo(&info); - - //now, put the path into the settings file - AutoRaiseSettings settings; - settings.SetAppPath(info.ref); } AutoRaiseApp::~AutoRaiseApp() diff --git a/src/apps/autoraise/AutoRaiseIcon.cpp b/src/apps/autoraise/AutoRaiseIcon.cpp index c5697607de..a3cd3d40d1 100644 --- a/src/apps/autoraise/AutoRaiseIcon.cpp +++ b/src/apps/autoraise/AutoRaiseIcon.cpp @@ -31,6 +31,21 @@ status_t removeFromDeskbar(void *) return B_OK; } + +static status_t +our_image(image_info& image) +{ + int32 cookie = 0; + while (get_next_image_info(B_CURRENT_TEAM, &cookie, &image) == B_OK) { + if ((char *)our_image >= (char *)image.text + && (char *)our_image <= (char *)image.text + image.text_size) + return B_OK; + } + + return B_ERROR; +} + + //************************************************** ConfigMenu::ConfigMenu(TrayView *tv, bool useMag) @@ -201,13 +216,10 @@ void TrayView::GetPreferredSize(float *w, float *h) void TrayView::_init() { thread_info ti; - status_t err; watching = false; _settings = new AutoRaiseSettings; - _appPath = _settings->AppPath(); - raise_delay = _settings->Delay(); current_window = 0; polling_delay = 100000; @@ -224,16 +236,31 @@ void TrayView::_init() resume_thread(poller_thread = spawn_thread(poller, "AutoRaise desktop " "poller", B_NORMAL_PRIORITY, (void *)this)); - //determine paths to icon files based on app path in settings file + image_info info; + { + status_t result = our_image(info); + if (result != B_OK) { + printf("Unable to lookup image_info for the AutoRaise image: %s\n", + strerror(result)); + removeFromDeskbar(NULL); + return; + } + } - BResources res; - BFile theapp(&_appPath, B_READ_ONLY); - if ((err = res.SetTo(&theapp)) != B_OK) { + BFile file(info.name, B_READ_ONLY); + if (file.InitCheck() != B_OK) { + printf("Unable to access AutoRaise image file: %s\n", + strerror(file.InitCheck())); + removeFromDeskbar(NULL); + return; + } - printf("Unable to find the app to get the resources !!!\n"); -// removeFromDeskbar(NULL); -// delete _settings; -// return; + BResources res(&file); + if (res.InitCheck() != B_OK) { + printf("Unable to load image resources: %s\n", + strerror(res.InitCheck())); + removeFromDeskbar(NULL); + return; } size_t bmsz; @@ -242,19 +269,22 @@ void TrayView::_init() p = (char *)res.LoadResource('MICN', ACTIVE_ICON, &bmsz); _activeIcon = new BBitmap(BRect(0, 0, B_MINI_ICON-1, B_MINI_ICON -1), B_CMAP8); - if (!p) + if (p == NULL) { puts("ERROR loading active icon"); - else - _activeIcon->SetBits(p, B_MINI_ICON*B_MINI_ICON, 0, B_CMAP8); + removeFromDeskbar(NULL); + return; + } + _activeIcon->SetBits(p, B_MINI_ICON * B_MINI_ICON, 0, B_CMAP8); p = (char *)res.LoadResource('MICN', INACTIVE_ICON, &bmsz); _inactiveIcon = new BBitmap(BRect(0, 0, B_MINI_ICON-1, B_MINI_ICON -1), B_CMAP8); - if (!p) + if (p == NULL) { puts("ERROR loading inactive icon"); - else - _inactiveIcon->SetBits(p, B_MINI_ICON*B_MINI_ICON, 0, B_CMAP8); - + removeFromDeskbar(NULL); + return; + } + _inactiveIcon->SetBits(p, B_MINI_ICON * B_MINI_ICON, 0, B_CMAP8); SetDrawingMode(B_OP_ALPHA); SetFlags(Flags() | B_WILL_DRAW); @@ -281,12 +311,8 @@ TrayView::~TrayView(){ //Dehydrate into a message (called by the DeskBar) status_t TrayView::Archive(BMessage *data, bool deep) const { -// BEntry appentry(&_appPath, true); -// BPath appPath(&appentry); status_t error=BView::Archive(data, deep); data->AddString("add_on", APP_SIG); -// data->AddFlat("_appPath", (BFlattenable *) &_appPath); - data->AddRef("_appPath", &_appPath); return error; } diff --git a/src/apps/autoraise/AutoRaiseIcon.h b/src/apps/autoraise/AutoRaiseIcon.h index 83164166cc..304e83f2b9 100644 --- a/src/apps/autoraise/AutoRaiseIcon.h +++ b/src/apps/autoraise/AutoRaiseIcon.h @@ -36,7 +36,6 @@ class TrayView:public BView{ private: BBitmap *_activeIcon, *_inactiveIcon; - entry_ref _appPath; bool watching; void _init(void); //initialization common to all constructors diff --git a/src/apps/autoraise/settings.cpp b/src/apps/autoraise/settings.cpp index bee3f1a1a8..9d83541977 100644 --- a/src/apps/autoraise/settings.cpp +++ b/src/apps/autoraise/settings.cpp @@ -16,8 +16,6 @@ _type AutoRaiseSettings::_name()\ CONF_ADDPROP(bool, Active) CONF_ADDPROP(bigtime_t, Delay) CONF_ADDPROP(int32, Mode) -//CONF_ADDPROP(BPath, AppPath) -CONF_ADDPROP(entry_ref, AppPath) #undef CONF_ADDPROP AutoRaiseSettings::AutoRaiseSettings() @@ -42,12 +40,6 @@ AutoRaiseSettings::AutoRaiseSettings() if (_settingsMessage.FindInt32(AR_MODE, &_confMode) != B_OK) printf("AutoRaiseSettings::AutoRaiseSettings();\tFailed to load mode from settings file. Using default\n"); - -// if (_settingsMessage.FindFlat(AR_APP_PATH, (BFlattenable *) &_appPath) != B_OK) -// printf("AutoRaiseSettings::AutoRaiseSettings();\tFailed to load application path.\n"); - - if (_settingsMessage.FindRef(AR_APP_PATH, &_confAppPath) != B_OK) - printf("AutoRaiseSettings::AutoRaiseSettings();\tFailed to load application path.\n"); } else { @@ -73,8 +65,6 @@ AutoRaiseSettings::~AutoRaiseSettings() _settingsMessage.AddBool(AR_ACTIVE, _confActive); _settingsMessage.AddInt64(AR_DELAY, _confDelay); _settingsMessage.AddInt32(AR_MODE, _confMode); -// _settingsMessage.AddFlat(AR_APP_PATH, &_appPath); - _settingsMessage.AddRef(AR_APP_PATH, &_confAppPath); //write message to settings file if (_settingsMessage.Flatten(&_settingsFile) != B_OK) diff --git a/src/apps/autoraise/settings.h b/src/apps/autoraise/settings.h index 9302b12931..37555ecac8 100644 --- a/src/apps/autoraise/settings.h +++ b/src/apps/autoraise/settings.h @@ -40,8 +40,6 @@ class AutoRaiseSettings { protected: BFile _settingsFile; -// BPath _appPath; - BMessage _settingsMessage; @@ -56,13 +54,9 @@ class AutoRaiseSettings CONF_ADDPROP(bool, Active) CONF_ADDPROP(bigtime_t, Delay) CONF_ADDPROP(int32, Mode) -//CONF_ADDPROP(BPath, AppPath) -CONF_ADDPROP(entry_ref, AppPath) }; #undef CONF_ADDPROP -#define AR_APP_PATH "ar:app_path" - #endif