| 1 |
|
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
#include <Alert.h> |
|---|
| 6 |
#include <Application.h> |
|---|
| 7 |
#include <Directory.h> |
|---|
| 8 |
#include <Message.h> |
|---|
| 9 |
#include <Messenger.h> |
|---|
| 10 |
#include <Roster.h> |
|---|
| 11 |
#include <be_apps/Deskbar/Deskbar.h> |
|---|
| 12 |
|
|---|
| 13 |
#include <string.h> |
|---|
| 14 |
|
|---|
| 15 |
#include "ThemesAddon.h" |
|---|
| 16 |
#include "UITheme.h" |
|---|
| 17 |
|
|---|
| 18 |
#ifdef SINGLE_BINARY |
|---|
| 19 |
#define instantiate_themes_addon instantiate_themes_addon_deskbar |
|---|
| 20 |
#endif |
|---|
| 21 |
|
|---|
| 22 |
#define A_NAME "Deskbar" |
|---|
| 23 |
#define A_MSGNAME Z_THEME_DESKBAR_SETTINGS |
|---|
| 24 |
#define A_DESCRIPTION "Deskbar on-screen position" |
|---|
| 25 |
|
|---|
| 26 |
class DeskbarThemesAddon : public ThemesAddon { |
|---|
| 27 |
public: |
|---|
| 28 |
DeskbarThemesAddon(); |
|---|
| 29 |
~DeskbarThemesAddon(); |
|---|
| 30 |
|
|---|
| 31 |
const char *Description(); |
|---|
| 32 |
|
|---|
| 33 |
status_t RunPreferencesPanel(); |
|---|
| 34 |
|
|---|
| 35 |
status_t AddNames(BMessage &names); |
|---|
| 36 |
|
|---|
| 37 |
status_t ApplyTheme(BMessage &theme, uint32 flags=0L); |
|---|
| 38 |
status_t MakeTheme(BMessage &theme, uint32 flags=0L); |
|---|
| 39 |
|
|---|
| 40 |
status_t ApplyDefaultTheme(uint32 flags=0L); |
|---|
| 41 |
}; |
|---|
| 42 |
|
|---|
| 43 |
DeskbarThemesAddon::DeskbarThemesAddon() |
|---|
| 44 |
: ThemesAddon(A_NAME, A_MSGNAME) |
|---|
| 45 |
{ |
|---|
| 46 |
} |
|---|
| 47 |
|
|---|
| 48 |
DeskbarThemesAddon::~DeskbarThemesAddon() |
|---|
| 49 |
{ |
|---|
| 50 |
} |
|---|
| 51 |
|
|---|
| 52 |
const char *DeskbarThemesAddon::Description() |
|---|
| 53 |
{ |
|---|
| 54 |
return A_DESCRIPTION; |
|---|
| 55 |
} |
|---|
| 56 |
|
|---|
| 57 |
status_t DeskbarThemesAddon::RunPreferencesPanel() |
|---|
| 58 |
{ |
|---|
| 59 |
status_t err; |
|---|
| 60 |
entry_ref ref; |
|---|
| 61 |
BEntry ent; |
|---|
| 62 |
err = ent.SetTo("/boot/beos/preferences/Deskbar"); |
|---|
| 63 |
if (!err) { |
|---|
| 64 |
err = ent.GetRef(&ref); |
|---|
| 65 |
if (!err) { |
|---|
| 66 |
err = be_roster->Launch(&ref); |
|---|
| 67 |
} |
|---|
| 68 |
} |
|---|
| 69 |
if (!err) |
|---|
| 70 |
return B_OK; |
|---|
| 71 |
err = ent.SetTo("/system/add-ons/Preferences/Deskbar"); |
|---|
| 72 |
if (!err) { |
|---|
| 73 |
err = ent.GetRef(&ref); |
|---|
| 74 |
if (!err) { |
|---|
| 75 |
err = be_roster->Launch(&ref); |
|---|
| 76 |
if (err) { |
|---|
| 77 |
BMessage msg(B_REFS_RECEIVED); |
|---|
| 78 |
msg.AddRef("refs", &ref); |
|---|
| 79 |
be_app_messenger.SendMessage(&msg); |
|---|
| 80 |
} |
|---|
| 81 |
} |
|---|
| 82 |
} |
|---|
| 83 |
return err; |
|---|
| 84 |
} |
|---|
| 85 |
|
|---|
| 86 |
status_t DeskbarThemesAddon::AddNames(BMessage &names) |
|---|
| 87 |
{ |
|---|
| 88 |
names.AddString(Z_THEME_DESKBAR_SETTINGS, "Deskbar position"); |
|---|
| 89 |
names.AddString("db:location", "Deskbar on-screen position"); |
|---|
| 90 |
names.AddString("db:expanded", "Deskbar is expanded"); |
|---|
| 91 |
return B_OK; |
|---|
| 92 |
} |
|---|
| 93 |
|
|---|
| 94 |
status_t DeskbarThemesAddon::ApplyTheme(BMessage &theme, uint32 flags) |
|---|
| 95 |
{ |
|---|
| 96 |
BMessage deskbar; |
|---|
| 97 |
status_t err; |
|---|
| 98 |
int32 loc = 5; |
|---|
| 99 |
bool expanded = true; |
|---|
| 100 |
BDeskbar db; |
|---|
| 101 |
|
|---|
| 102 |
if (!(flags & UI_THEME_SETTINGS_SET_ALL) || !(AddonFlags() & Z_THEME_ADDON_DO_SET_ALL)) |
|---|
| 103 |
return B_OK; |
|---|
| 104 |
|
|---|
| 105 |
err = MyMessage(theme, deskbar); |
|---|
| 106 |
if (err) |
|---|
| 107 |
return err; |
|---|
| 108 |
|
|---|
| 109 |
if (deskbar.FindInt32("db:location", &loc) != B_OK) |
|---|
| 110 |
return ENOENT; |
|---|
| 111 |
deskbar.FindBool("db:expanded", &expanded); |
|---|
| 112 |
return db.SetLocation((deskbar_location)loc, expanded); |
|---|
| 113 |
} |
|---|
| 114 |
|
|---|
| 115 |
status_t DeskbarThemesAddon::MakeTheme(BMessage &theme, uint32 flags) |
|---|
| 116 |
{ |
|---|
| 117 |
BMessage deskbar; |
|---|
| 118 |
status_t err; |
|---|
| 119 |
|
|---|
| 120 |
(void)flags; |
|---|
| 121 |
err = MyMessage(theme, deskbar); |
|---|
| 122 |
if (err) |
|---|
| 123 |
deskbar.MakeEmpty(); |
|---|
| 124 |
|
|---|
| 125 |
deskbar_location loc; |
|---|
| 126 |
bool expanded; |
|---|
| 127 |
BDeskbar db; |
|---|
| 128 |
|
|---|
| 129 |
deskbar.RemoveName("db:location"); |
|---|
| 130 |
deskbar.RemoveName("db:expanded"); |
|---|
| 131 |
|
|---|
| 132 |
loc = db.Location(&expanded); |
|---|
| 133 |
deskbar.AddInt32("db:location", (int32)loc); |
|---|
| 134 |
deskbar.AddBool("db:expanded", expanded); |
|---|
| 135 |
|
|---|
| 136 |
err = SetMyMessage(theme, deskbar); |
|---|
| 137 |
return err; |
|---|
| 138 |
} |
|---|
| 139 |
|
|---|
| 140 |
status_t DeskbarThemesAddon::ApplyDefaultTheme(uint32 flags) |
|---|
| 141 |
{ |
|---|
| 142 |
BMessage theme; |
|---|
| 143 |
BMessage deskbar; |
|---|
| 144 |
deskbar_location loc = B_DESKBAR_RIGHT_TOP; |
|---|
| 145 |
bool expanded = true; |
|---|
| 146 |
deskbar.AddInt32("db:location", (int32)loc); |
|---|
| 147 |
deskbar.AddBool("db:expanded", expanded); |
|---|
| 148 |
theme.AddMessage(A_MSGNAME, &deskbar); |
|---|
| 149 |
return ApplyTheme(theme, flags); |
|---|
| 150 |
} |
|---|
| 151 |
|
|---|
| 152 |
|
|---|
| 153 |
ThemesAddon *instantiate_themes_addon() |
|---|
| 154 |
{ |
|---|
| 155 |
return (ThemesAddon *) new DeskbarThemesAddon; |
|---|
| 156 |
} |
|---|