2008-10-01 08:28:35 +04:00
|
|
|
/*
|
|
|
|
* Copyright 2000-2008, François Revol, <revol@free.fr>. All rights reserved.
|
|
|
|
* Distributed under the terms of the MIT License.
|
|
|
|
*/
|
|
|
|
|
2008-01-11 21:06:15 +03:00
|
|
|
#include <Alert.h>
|
|
|
|
#include <Bitmap.h>
|
|
|
|
#include <Box.h>
|
|
|
|
#include <DataIO.h>
|
2008-02-01 06:27:09 +03:00
|
|
|
#include <Debug.h>
|
2008-01-11 21:06:15 +03:00
|
|
|
#include <Entry.h>
|
|
|
|
#include <File.h>
|
2008-01-12 02:49:42 +03:00
|
|
|
#include <BeBuild.h>
|
|
|
|
#ifdef B_ZETA_VERSION
|
|
|
|
#include <add-ons/pref_app/PrefPanel.h>
|
2008-01-11 21:06:15 +03:00
|
|
|
#include <locale/Locale.h>
|
|
|
|
#include <Separator.h>
|
2008-01-12 02:49:42 +03:00
|
|
|
#else
|
|
|
|
#define _T(v) v
|
|
|
|
#define B_PREF_APP_ENABLE_REVERT 'zPAE'
|
|
|
|
#define B_PREF_APP_SET_DEFAULTS 'zPAD'
|
|
|
|
#define B_PREF_APP_REVERT 'zPAR'
|
|
|
|
#define B_PREF_APP_ADDON_REF 'zPAA'
|
|
|
|
#endif
|
|
|
|
#include <Resources.h>
|
2008-01-11 21:06:15 +03:00
|
|
|
#include <TranslationUtils.h>
|
|
|
|
#include <TranslatorFormats.h>
|
2008-01-12 02:49:42 +03:00
|
|
|
#include <Roster.h>
|
2008-01-11 21:06:15 +03:00
|
|
|
|
|
|
|
#include <Button.h>
|
|
|
|
#include <ListView.h>
|
|
|
|
#include <interface/StringView.h>
|
|
|
|
#include <ScrollView.h>
|
|
|
|
#include <TextView.h>
|
|
|
|
|
|
|
|
#include <Application.h>
|
|
|
|
#include <MessageFilter.h>
|
|
|
|
|
2008-01-12 02:49:42 +03:00
|
|
|
#include <stdio.h>
|
|
|
|
|
2008-01-11 21:06:15 +03:00
|
|
|
#include "UITheme.h"
|
2008-01-11 22:04:19 +03:00
|
|
|
#include "TextInputAlert.h"
|
2008-01-11 21:06:15 +03:00
|
|
|
|
|
|
|
extern status_t ScaleBitmap(const BBitmap& inBitmap, BBitmap& outBitmap);
|
|
|
|
|
|
|
|
/* gui */
|
|
|
|
//#include "ThemeSelector.h"
|
|
|
|
#include "ThemeInterfaceView.h"
|
|
|
|
#include "ThemeItem.h"
|
|
|
|
#include "ThemeAddonItem.h"
|
|
|
|
|
|
|
|
/* impl */
|
|
|
|
#include "ThemeManager.h"
|
|
|
|
|
|
|
|
const uint32 kThemeChanged = 'mThC';
|
|
|
|
const uint32 kApplyThemeBtn = 'TmAp';
|
|
|
|
const uint32 kCreateThemeBtn = 'TmCr';
|
|
|
|
const uint32 kReallyCreateTheme = 'TmCR';
|
|
|
|
const uint32 kSaveThemeBtn = 'TmSa';
|
|
|
|
const uint32 kDeleteThemeBtn = 'TmDe';
|
|
|
|
const uint32 kHidePreviewBtn = 'TmHP';
|
|
|
|
const uint32 kThemeSelected = 'TmTS';
|
|
|
|
const uint32 kMakeScreenshot = 'TmMS';
|
|
|
|
|
|
|
|
const uint32 kHideSSPulse = 'TmH1';
|
|
|
|
const uint32 kShowSSPulse = 'TmH2';
|
|
|
|
|
|
|
|
static const uint32 skOnlineThemes = 'TmOL';
|
|
|
|
static char* skThemeURL = "http://www.zeta-os.com/cms/download.php?list.4";
|
|
|
|
|
|
|
|
#define HIDESS_OFFSET (Bounds().Width()/2 - 130)
|
2008-10-01 07:37:33 +04:00
|
|
|
|
|
|
|
|
|
|
|
// #pragma mark - refs_filter
|
|
|
|
|
|
|
|
|
|
|
|
filter_result
|
|
|
|
refs_filter(BMessage *message, BHandler **handler, BMessageFilter *filter)
|
2008-01-11 21:06:15 +03:00
|
|
|
{
|
|
|
|
(void)handler;
|
|
|
|
(void)filter;
|
|
|
|
switch (message->what) {
|
2008-10-01 07:37:33 +04:00
|
|
|
case B_REFS_RECEIVED:
|
|
|
|
message->PrintToStream();
|
|
|
|
break;
|
2008-01-11 21:06:15 +03:00
|
|
|
}
|
|
|
|
return B_DISPATCH_MESSAGE;
|
|
|
|
}
|
|
|
|
|
2008-10-01 07:37:33 +04:00
|
|
|
|
|
|
|
// #pragma mark - MyInvoker
|
|
|
|
|
|
|
|
|
2008-01-14 05:00:42 +03:00
|
|
|
class MyInvoker : public BInvoker {
|
2008-10-01 07:37:33 +04:00
|
|
|
public:
|
|
|
|
MyInvoker(BMessage* message,
|
|
|
|
const BHandler* handler,
|
|
|
|
const BLooper* looper = NULL);
|
|
|
|
virtual ~MyInvoker();
|
|
|
|
virtual status_t Invoke(BMessage* message = NULL);
|
|
|
|
void SetOwner(TextInputAlert *alert);
|
|
|
|
private:
|
|
|
|
TextInputAlert* fOwner;
|
2008-01-14 05:00:42 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2008-10-01 07:37:33 +04:00
|
|
|
MyInvoker::MyInvoker(BMessage* message,
|
|
|
|
const BHandler* handler,
|
|
|
|
const BLooper* looper)
|
2008-01-14 05:00:42 +03:00
|
|
|
: BInvoker(message, handler, looper)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
MyInvoker::~MyInvoker()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
status_t
|
|
|
|
MyInvoker::Invoke(BMessage* message)
|
|
|
|
{
|
|
|
|
BMessage *out = Message();
|
|
|
|
if (out) {
|
|
|
|
if (out->ReplaceString("text", fOwner->TextControl()->TextView()->Text()) == B_OK ||
|
|
|
|
out->AddString("text", fOwner->TextControl()->TextView()->Text()) == B_OK)
|
|
|
|
return BInvoker::Invoke();
|
|
|
|
}
|
|
|
|
return EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
MyInvoker::SetOwner(TextInputAlert *alert)
|
|
|
|
{
|
|
|
|
fOwner = alert;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-10-01 07:37:33 +04:00
|
|
|
// #pragma mark -
|
|
|
|
|
|
|
|
|
2008-01-11 21:06:15 +03:00
|
|
|
//extern "C" BView *get_pref_view(const BRect& Bounds)
|
2008-10-01 07:37:33 +04:00
|
|
|
extern "C" BView *
|
|
|
|
themes_pref(const BRect& Bounds)
|
2008-01-11 21:06:15 +03:00
|
|
|
{
|
|
|
|
return new ThemeInterfaceView(Bounds);
|
|
|
|
}
|
|
|
|
|
2008-10-01 07:37:33 +04:00
|
|
|
|
|
|
|
// #pragma mark - ThemeInterfaceView
|
|
|
|
|
|
|
|
|
2008-01-11 21:06:15 +03:00
|
|
|
ThemeInterfaceView::ThemeInterfaceView(BRect _bounds)
|
2008-10-01 07:37:33 +04:00
|
|
|
: BView(_bounds, "Themes", B_FOLLOW_ALL_SIDES, B_WILL_DRAW),
|
|
|
|
fThemeManager(NULL),
|
|
|
|
fScreenshotPaneHidden(false),
|
|
|
|
fHasScreenshot(false),
|
|
|
|
fPopupInvoker(NULL),
|
|
|
|
fBox(NULL)
|
2008-01-11 21:06:15 +03:00
|
|
|
{
|
|
|
|
/*
|
|
|
|
BMessageFilter *filt = new BMessageFilter(B_ANY_DELIVERY, B_ANY_SOURCE, refs_filter);
|
|
|
|
be_app->Lock();
|
|
|
|
be_app->AddCommonFilter(filt);
|
|
|
|
be_app->Unlock();
|
|
|
|
*/
|
|
|
|
}
|
|
|
|
|
2008-10-01 07:37:33 +04:00
|
|
|
|
2008-01-11 21:06:15 +03:00
|
|
|
ThemeInterfaceView::~ThemeInterfaceView()
|
|
|
|
{
|
|
|
|
delete fPopupInvoker;
|
|
|
|
delete fThemeManager;
|
|
|
|
}
|
|
|
|
|
2008-10-01 07:37:33 +04:00
|
|
|
|
2008-01-11 21:06:15 +03:00
|
|
|
void
|
|
|
|
ThemeInterfaceView::AllAttached()
|
|
|
|
{
|
|
|
|
BView::AllAttached();
|
|
|
|
|
2008-01-14 05:00:42 +03:00
|
|
|
fPopupInvoker = new MyInvoker(new BMessage(kReallyCreateTheme), this);
|
2008-01-12 02:49:42 +03:00
|
|
|
#ifdef B_BEOS_VERSION_DANO
|
2008-01-11 21:06:15 +03:00
|
|
|
SetViewUIColor(B_UI_PANEL_BACKGROUND_COLOR);
|
2008-01-12 02:49:42 +03:00
|
|
|
#else
|
|
|
|
SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
|
|
|
|
#endif
|
2008-01-11 21:06:15 +03:00
|
|
|
|
|
|
|
fThemeManager = new ThemeManager;
|
|
|
|
|
|
|
|
BRect frame = Bounds();
|
|
|
|
frame.InsetBy(10.0, 10.0);
|
|
|
|
|
|
|
|
// add the theme listview
|
|
|
|
BRect list_frame = frame;
|
|
|
|
list_frame.right = 130;
|
|
|
|
fThemeList = new BListView(list_frame.InsetByCopy(3.0, 3.0), "themelist");
|
|
|
|
fThemeListSV = new BScrollView("themelistsv", fThemeList, B_FOLLOW_LEFT|B_FOLLOW_TOP, 0, false, true);
|
|
|
|
AddChild(fThemeListSV);
|
|
|
|
fThemeList->SetSelectionMessage(new BMessage(kThemeSelected));
|
|
|
|
fThemeList->SetInvocationMessage(new BMessage(kApplyThemeBtn));
|
|
|
|
fThemeList->SetTarget(this);
|
|
|
|
|
|
|
|
// buttons...
|
|
|
|
fNewBtn = new BButton(BRect(), "create", _T("New"), new BMessage(kCreateThemeBtn));
|
|
|
|
AddChild(fNewBtn);
|
|
|
|
fNewBtn->SetTarget(this);
|
|
|
|
fNewBtn->ResizeToPreferred();
|
|
|
|
fNewBtn->MoveTo(fThemeListSV->Frame().right + 15.0, frame.bottom - fNewBtn->Bounds().Height());
|
|
|
|
BPoint lt = fNewBtn->Frame().LeftTop();
|
|
|
|
lt.x = fNewBtn->Frame().right + 10.0;
|
|
|
|
|
|
|
|
lt.x = fNewBtn->Frame().right + 10.0;
|
|
|
|
fSaveBtn = new BButton(BRect(), "save", _T("Save"), new BMessage(kSaveThemeBtn));
|
|
|
|
AddChild(fSaveBtn);
|
|
|
|
fSaveBtn->SetTarget(this);
|
|
|
|
fSaveBtn->ResizeToPreferred();
|
|
|
|
fSaveBtn->MoveTo(lt);
|
|
|
|
|
|
|
|
lt.x = fSaveBtn->Frame().right + 10.0;
|
|
|
|
fDeleteBtn = new BButton(BRect(), "delete", _T("Delete"), new BMessage(kDeleteThemeBtn));
|
|
|
|
AddChild(fDeleteBtn);
|
|
|
|
fDeleteBtn->SetTarget(this);
|
|
|
|
fDeleteBtn->ResizeToPreferred();
|
|
|
|
fDeleteBtn->MoveTo(lt);
|
|
|
|
|
|
|
|
// buttons...
|
|
|
|
fSetShotBtn = new BButton(BRect(), "makeshot", _T("Add Screenshot"), new BMessage(kMakeScreenshot), B_FOLLOW_RIGHT | B_FOLLOW_TOP);
|
|
|
|
AddChild(fSetShotBtn);
|
|
|
|
fSetShotBtn->SetTarget(this);
|
|
|
|
fSetShotBtn->ResizeToPreferred();
|
|
|
|
|
|
|
|
fShowSSPaneBtn = new BButton(BRect(), "hidess", _T("Show Options"), new BMessage(kHidePreviewBtn), B_FOLLOW_RIGHT | B_FOLLOW_TOP);
|
|
|
|
AddChild(fShowSSPaneBtn);
|
|
|
|
fShowSSPaneBtn->SetTarget(this);
|
|
|
|
fShowSSPaneBtn->ResizeToPreferred();
|
|
|
|
|
|
|
|
fApplyBtn = new BButton(BRect(), "apply", _T("Apply"), new BMessage(kApplyThemeBtn), B_FOLLOW_RIGHT | B_FOLLOW_TOP);
|
|
|
|
AddChild(fApplyBtn);
|
|
|
|
fApplyBtn->ResizeToPreferred();
|
|
|
|
fApplyBtn->SetTarget(this);
|
|
|
|
|
|
|
|
float widest = max_c(fSetShotBtn->Bounds().Width(), fShowSSPaneBtn->Bounds().Width());
|
|
|
|
widest = max_c(widest, fApplyBtn->Bounds().Width());
|
|
|
|
float height = fSetShotBtn->Bounds().Height();
|
|
|
|
fSetShotBtn->ResizeTo(widest, height);
|
|
|
|
fShowSSPaneBtn->ResizeTo(widest, height);
|
|
|
|
fApplyBtn->ResizeTo(widest, height);
|
|
|
|
|
|
|
|
fSetShotBtn->MoveTo(frame.right - widest, frame.top + 5.0);
|
|
|
|
fShowSSPaneBtn->MoveTo(frame.right - widest, fSetShotBtn->Frame().bottom + 10.0);
|
|
|
|
fApplyBtn->MoveTo(frame.right - widest, fNewBtn->Frame().top - fApplyBtn->Bounds().Height() - 10);
|
|
|
|
|
|
|
|
// add the preview screen
|
|
|
|
BRect preview_frame(fNewBtn->Frame().left, fThemeListSV->Frame().top, frame.right - widest - 10, fNewBtn->Frame().top - 10);
|
|
|
|
|
|
|
|
fBox = new BBox(preview_frame, "preview", B_FOLLOW_ALL);
|
|
|
|
AddChild(fBox);
|
|
|
|
fBox->SetLabel(_T("Preview"));
|
|
|
|
|
|
|
|
preview_frame.InsetBy(10.0, 15.0);
|
|
|
|
preview_frame.OffsetTo(10.0, 20.0);
|
|
|
|
fScreenshotPane = new BView(preview_frame, "screenshot", B_FOLLOW_ALL, B_WILL_DRAW);
|
|
|
|
fBox->AddChild(fScreenshotPane);
|
2008-01-12 04:05:37 +03:00
|
|
|
#ifdef B_BEOS_VERSION_DANO
|
2008-01-11 21:06:15 +03:00
|
|
|
fScreenshotPane->SetViewUIColor(B_UI_PANEL_BACKGROUND_COLOR);
|
2008-01-12 04:05:37 +03:00
|
|
|
#else
|
|
|
|
fScreenshotPane->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
|
|
|
|
#endif
|
2008-01-11 21:06:15 +03:00
|
|
|
|
2008-11-09 20:36:38 +03:00
|
|
|
fScreenshotNone = new BStringView(BRect(), "sshotnone", _T("No Theme selected"), B_FOLLOW_ALL);
|
2008-01-11 21:06:15 +03:00
|
|
|
fScreenshotNone->SetFontSize(20.0);
|
|
|
|
fScreenshotNone->SetAlignment(B_ALIGN_CENTER);
|
|
|
|
fBox->AddChild(fScreenshotNone);
|
|
|
|
fScreenshotNone->ResizeToPreferred();
|
|
|
|
fScreenshotNone->ResizeTo(fBox->Bounds().Width() - 10.0, fScreenshotNone->Bounds().Height());
|
|
|
|
fScreenshotNone->MoveTo(fBox->Bounds().left + 5.0,
|
|
|
|
((fBox->Frame().Height() - fScreenshotNone->Frame().Height()) / 2.0));
|
|
|
|
|
|
|
|
// Theme hyperlink
|
2008-01-11 22:04:19 +03:00
|
|
|
/*
|
2008-01-11 21:06:15 +03:00
|
|
|
BStringView* hlink = new BStringView(BRect(), "theme_hyperlink", _T("More themes online"), new BMessage(skOnlineThemes), B_FOLLOW_RIGHT | B_FOLLOW_BOTTOM);
|
|
|
|
AddChild(hlink);
|
|
|
|
hlink->SetClickText(hlink->GetText(), *this);
|
|
|
|
hlink->ResizeToPreferred();
|
|
|
|
hlink->MoveTo(frame.right - hlink->Bounds().Width(), fNewBtn->Frame().top + 5);
|
2008-01-11 22:04:19 +03:00
|
|
|
*/
|
2008-01-11 21:06:15 +03:00
|
|
|
|
|
|
|
// the addons list view
|
|
|
|
preview_frame = fBox->Frame();
|
|
|
|
preview_frame.InsetBy(3.0, 3.0);
|
|
|
|
preview_frame.right -= B_V_SCROLL_BAR_WIDTH;
|
|
|
|
fAddonList = new BListView(preview_frame, "addonlist");
|
|
|
|
fAddonListSV = new BScrollView("addonlistsv", fAddonList, B_FOLLOW_LEFT|B_FOLLOW_TOP, 0, false, true);
|
|
|
|
AddChild(fAddonListSV);
|
|
|
|
fAddonList->SetSelectionMessage(new BMessage(kThemeSelected));
|
|
|
|
fAddonList->SetInvocationMessage(new BMessage(kApplyThemeBtn));
|
|
|
|
fAddonList->SetTarget(this);
|
|
|
|
fAddonListSV->Hide();
|
|
|
|
|
|
|
|
PopulateAddonList();
|
2008-01-14 05:00:42 +03:00
|
|
|
PopulateThemeList();
|
2008-01-11 21:06:15 +03:00
|
|
|
}
|
|
|
|
|
2008-10-01 07:37:33 +04:00
|
|
|
|
2008-01-11 21:06:15 +03:00
|
|
|
void
|
|
|
|
ThemeInterfaceView::MessageReceived(BMessage *_msg)
|
|
|
|
{
|
|
|
|
ThemeManager *tman;
|
|
|
|
int32 value;
|
|
|
|
int32 id;
|
2008-10-01 07:37:33 +04:00
|
|
|
|
2008-01-11 21:06:15 +03:00
|
|
|
switch(_msg->what)
|
|
|
|
{
|
|
|
|
case B_REFS_RECEIVED:
|
|
|
|
_msg->PrintToStream();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case kMakeScreenshot:
|
|
|
|
AddScreenshot();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case kThemeSelected:
|
|
|
|
ThemeSelected();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case kHidePreviewBtn:
|
|
|
|
HideScreenshotPane(!IsScreenshotPaneHidden());
|
|
|
|
break;
|
|
|
|
|
|
|
|
case kApplyThemeBtn:
|
|
|
|
ApplySelected();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case kCreateThemeBtn:
|
|
|
|
{
|
2008-01-14 05:00:42 +03:00
|
|
|
TextInputAlert *alert = new TextInputAlert("New name", "New Theme Name", "My Theme", "Ok");
|
|
|
|
fPopupInvoker->SetOwner(alert);
|
2008-01-11 22:04:19 +03:00
|
|
|
alert->Go(fPopupInvoker);
|
2008-01-11 21:06:15 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case kReallyCreateTheme:
|
|
|
|
{
|
|
|
|
const char *name;
|
|
|
|
if (_msg->FindString("text", &name) < B_OK)
|
|
|
|
break;
|
|
|
|
CreateNew(name);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case kSaveThemeBtn:
|
|
|
|
SaveSelected();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case kDeleteThemeBtn:
|
|
|
|
DeleteSelected();
|
|
|
|
break;
|
|
|
|
#if 0
|
|
|
|
case kColorsChanged:
|
|
|
|
case kGeneralChanged:
|
|
|
|
case kFontsChanged:
|
|
|
|
{
|
|
|
|
BMessenger msgr (Parent());
|
|
|
|
msgr.SendMessage(B_PREF_APP_ENABLE_REVERT);
|
|
|
|
BMessage changes;
|
|
|
|
if (_msg->FindMessage("changes", &changes) == B_OK)
|
|
|
|
{
|
|
|
|
update_ui_settings(changes);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
case B_PREF_APP_SET_DEFAULTS:
|
|
|
|
{
|
|
|
|
ApplyDefaults();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case B_PREF_APP_REVERT:
|
|
|
|
{
|
|
|
|
Revert();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case B_PREF_APP_ADDON_REF:
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case kThemeChanged:
|
|
|
|
{
|
|
|
|
/* BMessage data;
|
|
|
|
BMessage names;
|
|
|
|
get_ui_settings(&data, &names);
|
|
|
|
fColorSelector->Update(data);
|
|
|
|
fFontSelector->Refresh();
|
|
|
|
fGeneralSelector->Refresh(data);
|
|
|
|
*/
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case CB_APPLY:
|
|
|
|
tman = GetThemeManager();
|
|
|
|
_msg->PrintToStream();
|
|
|
|
if (_msg->FindInt32("be:value", &value) < B_OK)
|
|
|
|
value = false;
|
|
|
|
if (_msg->FindInt32("addon", &id) < B_OK)
|
|
|
|
break;
|
|
|
|
//tman->SetAddonFlags(id, (tman->AddonFlags(id) & ~Z_THEME_ADDON_DO_SET_ALL));
|
|
|
|
tman->SetAddonFlags(id, (tman->AddonFlags(id) & ~Z_THEME_ADDON_DO_SET_ALL) | (value?Z_THEME_ADDON_DO_SET_ALL:0));
|
|
|
|
break;
|
|
|
|
|
|
|
|
case CB_SAVE:
|
|
|
|
tman = GetThemeManager();
|
|
|
|
_msg->PrintToStream();
|
|
|
|
if (_msg->FindInt32("be:value", &value) < B_OK)
|
|
|
|
value = false;
|
|
|
|
if (_msg->FindInt32("addon", &id) < B_OK)
|
|
|
|
break;
|
|
|
|
tman->SetAddonFlags(id, (tman->AddonFlags(id) & ~Z_THEME_ADDON_DO_RETRIEVE) | (value?Z_THEME_ADDON_DO_RETRIEVE:0));
|
|
|
|
break;
|
|
|
|
|
|
|
|
case BTN_PREFS:
|
|
|
|
tman = GetThemeManager();
|
|
|
|
if (_msg->FindInt32("addon", &id) < B_OK)
|
|
|
|
break;
|
|
|
|
tman->RunPreferencesPanel(id);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case kHideSSPulse:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case kShowSSPulse:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case skOnlineThemes:
|
|
|
|
be_roster->Launch( "application/x-vnd.Mozilla-Firefox", 1, &skThemeURL);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
{
|
|
|
|
BView::MessageReceived(_msg);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-10-01 07:37:33 +04:00
|
|
|
|
|
|
|
ThemeManager*
|
|
|
|
ThemeInterfaceView::GetThemeManager()
|
2008-01-11 21:06:15 +03:00
|
|
|
{
|
|
|
|
return fThemeManager;
|
|
|
|
}
|
|
|
|
|
2008-10-01 07:37:33 +04:00
|
|
|
|
|
|
|
void
|
|
|
|
ThemeInterfaceView::HideScreenshotPane(bool hide)
|
2008-01-11 21:06:15 +03:00
|
|
|
{
|
|
|
|
BString lbl;
|
|
|
|
if (IsScreenshotPaneHidden() && hide)
|
|
|
|
return;
|
|
|
|
if (!IsScreenshotPaneHidden() && !hide)
|
|
|
|
return;
|
|
|
|
fScreenshotPaneHidden = hide;
|
|
|
|
|
|
|
|
if (hide)
|
|
|
|
{
|
|
|
|
if (!fScreenshotPane->IsHidden())
|
|
|
|
{
|
|
|
|
fBox->Hide();
|
|
|
|
fAddonListSV->Show();
|
|
|
|
}
|
|
|
|
fShowSSPaneBtn->SetLabel(_T("Show Preview"));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
fShowSSPaneBtn->SetLabel(_T("Show Options"));
|
|
|
|
if (fScreenshotPane->IsHidden())
|
|
|
|
{
|
|
|
|
fBox->Show();
|
|
|
|
fAddonListSV->Hide();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// TODO
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-10-01 07:37:33 +04:00
|
|
|
|
|
|
|
bool
|
|
|
|
ThemeInterfaceView::IsScreenshotPaneHidden()
|
2008-01-11 21:06:15 +03:00
|
|
|
{
|
|
|
|
return fScreenshotPaneHidden;
|
|
|
|
}
|
|
|
|
|
2008-10-01 07:37:33 +04:00
|
|
|
|
|
|
|
void
|
|
|
|
ThemeInterfaceView::PopulateThemeList()
|
2008-01-14 05:00:42 +03:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
BControl *c;
|
|
|
|
for (i = 0; ChildAt(i); i++) {
|
|
|
|
c = dynamic_cast<BControl *>(ChildAt(i));
|
|
|
|
if (c)
|
|
|
|
c->SetEnabled(false);
|
|
|
|
}
|
2008-10-01 07:37:33 +04:00
|
|
|
thread_id tid = spawn_thread(_ThemeListPopulatorTh, "ThemeListPopulator",
|
|
|
|
B_LOW_PRIORITY, this);
|
2008-01-14 05:00:42 +03:00
|
|
|
resume_thread(tid);
|
|
|
|
}
|
|
|
|
|
2008-10-01 07:37:33 +04:00
|
|
|
|
|
|
|
int32
|
|
|
|
ThemeInterfaceView::_ThemeListPopulatorTh(void *arg)
|
2008-01-14 05:00:42 +03:00
|
|
|
{
|
|
|
|
ThemeInterfaceView *_this = (ThemeInterfaceView *)arg;
|
|
|
|
_this->_ThemeListPopulator();
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-10-01 07:37:33 +04:00
|
|
|
|
|
|
|
void
|
|
|
|
ThemeInterfaceView::_ThemeListPopulator()
|
2008-01-11 21:06:15 +03:00
|
|
|
{
|
|
|
|
status_t err;
|
|
|
|
int32 i, count;
|
2008-02-01 06:15:40 +03:00
|
|
|
int32 importer;
|
2008-01-11 21:06:15 +03:00
|
|
|
BString name;
|
|
|
|
ThemeItem *ti;
|
|
|
|
bool isro;
|
2008-01-14 05:00:42 +03:00
|
|
|
|
2008-01-11 21:06:15 +03:00
|
|
|
ThemeManager* tman = GetThemeManager();
|
2008-01-14 05:00:42 +03:00
|
|
|
tman->LoadThemes();
|
|
|
|
|
2008-01-11 21:06:15 +03:00
|
|
|
count = tman->CountThemes();
|
2008-02-01 06:15:40 +03:00
|
|
|
|
2008-01-14 05:00:42 +03:00
|
|
|
LockLooper();
|
2008-01-11 21:06:15 +03:00
|
|
|
fThemeList->MakeEmpty();
|
2008-01-14 05:00:42 +03:00
|
|
|
UnlockLooper();
|
2008-02-01 06:15:40 +03:00
|
|
|
|
|
|
|
// native themes
|
2008-01-11 21:06:15 +03:00
|
|
|
for (i = 0; i < count; i++) {
|
|
|
|
err = tman->ThemeName(i, name);
|
|
|
|
isro = tman->ThemeIsReadOnly(i);
|
|
|
|
if (err)
|
|
|
|
continue;
|
|
|
|
ti = new ThemeItem(i, name.String(), isro);
|
2008-01-14 05:00:42 +03:00
|
|
|
LockLooper();
|
2008-01-11 21:06:15 +03:00
|
|
|
fThemeList->AddItem(ti);
|
2008-01-14 05:00:42 +03:00
|
|
|
UnlockLooper();
|
|
|
|
}
|
|
|
|
|
2008-02-01 06:15:40 +03:00
|
|
|
// for each importer
|
|
|
|
for (importer = 0; importer < tman->CountThemeImporters(); importer++) {
|
|
|
|
err = tman->ImportThemesFor(importer);
|
|
|
|
if (err < 0)
|
|
|
|
continue;
|
|
|
|
PRINT(("Imports for %s: %d\n", tman->ThemeImporterAt(importer), (tman->CountThemes() - count)));
|
|
|
|
if (tman->CountThemes() == count)
|
|
|
|
continue; // nothing found
|
|
|
|
// separator item
|
|
|
|
name = "Imported (";
|
|
|
|
name << tman->ThemeImporterAt(importer) << ")";
|
|
|
|
BStringItem *si = new BStringItem(name.String());
|
|
|
|
si->SetEnabled(false);
|
|
|
|
LockLooper();
|
|
|
|
fThemeList->AddItem(si);
|
|
|
|
UnlockLooper();
|
|
|
|
// add new themes
|
|
|
|
count = tman->CountThemes();
|
|
|
|
for (; i < count; i++) {
|
|
|
|
err = tman->ThemeName(i, name);
|
|
|
|
isro = true;//tman->ThemeIsReadOnly(i);
|
|
|
|
if (err)
|
|
|
|
continue;
|
|
|
|
ti = new ThemeItem(i, name.String(), isro);
|
|
|
|
LockLooper();
|
|
|
|
fThemeList->AddItem(ti);
|
|
|
|
UnlockLooper();
|
2008-10-01 07:37:33 +04:00
|
|
|
// rest a bit
|
|
|
|
snooze(1000);
|
2008-02-01 06:15:40 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
// enable controls again
|
2008-01-14 05:00:42 +03:00
|
|
|
BControl *c;
|
|
|
|
LockLooper();
|
|
|
|
for (i = 0; ChildAt(i); i++) {
|
|
|
|
c = dynamic_cast<BControl *>(ChildAt(i));
|
|
|
|
if (c)
|
|
|
|
c->SetEnabled(true);
|
2008-01-11 21:06:15 +03:00
|
|
|
}
|
2008-01-14 05:00:42 +03:00
|
|
|
UnlockLooper();
|
2008-01-11 21:06:15 +03:00
|
|
|
}
|
|
|
|
|
2008-10-01 07:37:33 +04:00
|
|
|
|
|
|
|
void
|
|
|
|
ThemeInterfaceView::PopulateAddonList()
|
2008-01-11 21:06:15 +03:00
|
|
|
{
|
|
|
|
int32 i, count;
|
|
|
|
ViewItem *vi;
|
|
|
|
ThemeManager* tman = GetThemeManager();
|
|
|
|
count = tman->CountAddons();
|
|
|
|
fAddonList->MakeEmpty();
|
|
|
|
for (i = 0; i < count; i++) {
|
|
|
|
vi = new ThemeAddonItem(BRect(0,0,200,52), this, i);
|
|
|
|
fAddonList->AddItem(vi);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-10-01 07:37:33 +04:00
|
|
|
|
|
|
|
status_t
|
|
|
|
ThemeInterfaceView::Revert()
|
2008-01-11 21:06:15 +03:00
|
|
|
{
|
|
|
|
status_t err = B_OK;
|
|
|
|
ThemeManager* tman = GetThemeManager();
|
|
|
|
|
|
|
|
if (tman->CanRevert())
|
|
|
|
err = tman->RestoreCurrent();
|
|
|
|
if (err)
|
|
|
|
return err;
|
|
|
|
|
|
|
|
return B_OK;
|
|
|
|
}
|
|
|
|
|
2008-10-01 07:37:33 +04:00
|
|
|
|
|
|
|
status_t
|
|
|
|
ThemeInterfaceView::ApplyDefaults()
|
2008-01-11 21:06:15 +03:00
|
|
|
{
|
|
|
|
status_t err = B_OK;
|
|
|
|
ThemeManager* tman = GetThemeManager();
|
|
|
|
|
|
|
|
SetIsRevertable();
|
|
|
|
|
|
|
|
err = tman->ApplyDefaultTheme();
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2008-10-01 07:37:33 +04:00
|
|
|
|
|
|
|
status_t
|
|
|
|
ThemeInterfaceView::ApplySelected()
|
2008-01-11 21:06:15 +03:00
|
|
|
{
|
|
|
|
status_t err;
|
|
|
|
ThemeManager* tman = GetThemeManager();
|
|
|
|
int32 id;
|
|
|
|
ThemeItem *item;
|
|
|
|
// find selected theme
|
|
|
|
id = fThemeList->CurrentSelection(0);
|
|
|
|
if (id < 0)
|
|
|
|
return ENOENT;
|
|
|
|
item = dynamic_cast<ThemeItem *>(fThemeList->ItemAt(id));
|
|
|
|
if (!item)
|
|
|
|
return ENOENT;
|
|
|
|
id = item->ThemeId();
|
|
|
|
if (id < 0)
|
|
|
|
return ENOENT;
|
|
|
|
SetIsRevertable();
|
|
|
|
err = tman->ApplyTheme(id);
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2008-10-01 07:37:33 +04:00
|
|
|
|
|
|
|
status_t
|
|
|
|
ThemeInterfaceView::CreateNew(const char *name)
|
2008-01-11 21:06:15 +03:00
|
|
|
{
|
|
|
|
status_t err;
|
|
|
|
ThemeManager* tman = GetThemeManager();
|
|
|
|
int32 id;
|
|
|
|
ThemeItem *ti;
|
|
|
|
BString n(name);
|
|
|
|
|
|
|
|
id = tman->MakeTheme();
|
|
|
|
if (id < 0)
|
|
|
|
return B_ERROR;
|
|
|
|
err = tman->SetThemeName(id, name);
|
|
|
|
if (err)
|
|
|
|
return err;
|
|
|
|
err = tman->ThemeName(id, n);
|
|
|
|
if (err)
|
|
|
|
return err;
|
|
|
|
err = tman->SaveTheme(id, true);
|
|
|
|
if (err)
|
|
|
|
return err;
|
|
|
|
ti = new ThemeItem(id, n.String(), false);
|
|
|
|
fThemeList->AddItem(ti);
|
|
|
|
return B_OK;
|
|
|
|
}
|
|
|
|
|
2008-10-01 07:37:33 +04:00
|
|
|
|
|
|
|
status_t
|
|
|
|
ThemeInterfaceView::SaveSelected()
|
2008-01-11 21:06:15 +03:00
|
|
|
{
|
|
|
|
status_t err;
|
|
|
|
ThemeManager* tman = GetThemeManager();
|
|
|
|
int32 id;
|
|
|
|
ThemeItem *item;
|
|
|
|
BMessage theme;
|
|
|
|
// find selected theme
|
|
|
|
id = fThemeList->CurrentSelection(0);
|
|
|
|
if (id < 0)
|
|
|
|
return B_OK;
|
|
|
|
item = dynamic_cast<ThemeItem *>(fThemeList->ItemAt(id));
|
|
|
|
if (!item)
|
|
|
|
return AError(__FUNCTION__, ENOENT);
|
|
|
|
if (item->IsReadOnly())
|
|
|
|
return AError(__FUNCTION__, B_READ_ONLY_DEVICE);
|
|
|
|
id = item->ThemeId();
|
|
|
|
if (id < 0)
|
|
|
|
return AError(__FUNCTION__, ENOENT);
|
|
|
|
|
|
|
|
err = tman->UpdateTheme(id);
|
|
|
|
if (err)
|
|
|
|
return AError(__FUNCTION__, err);
|
|
|
|
err = tman->SaveTheme(id);
|
|
|
|
if (err)
|
|
|
|
return AError(__FUNCTION__, err);
|
|
|
|
//err = tman->ApplyTheme(theme);
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2008-10-01 07:37:33 +04:00
|
|
|
|
|
|
|
status_t
|
|
|
|
ThemeInterfaceView::DeleteSelected()
|
2008-01-11 21:06:15 +03:00
|
|
|
{
|
|
|
|
status_t err;
|
|
|
|
ThemeManager* tman = GetThemeManager();
|
|
|
|
int32 id;
|
|
|
|
ThemeItem *item;
|
|
|
|
BMessage theme;
|
|
|
|
// find selected theme
|
|
|
|
id = fThemeList->CurrentSelection(0);
|
|
|
|
if (id < 0)
|
|
|
|
return B_OK;
|
|
|
|
item = dynamic_cast<ThemeItem *>(fThemeList->ItemAt(id));
|
|
|
|
if (!item)
|
|
|
|
return AError(__FUNCTION__, ENOENT);
|
|
|
|
if (item->IsReadOnly())
|
|
|
|
return AError(__FUNCTION__, B_READ_ONLY_DEVICE);
|
|
|
|
id = item->ThemeId();
|
|
|
|
if (id < 0)
|
|
|
|
return AError(__FUNCTION__, ENOENT);
|
|
|
|
// then apply
|
|
|
|
err = tman->DeleteTheme(id);
|
|
|
|
if (err)
|
|
|
|
return AError(__FUNCTION__, err);
|
|
|
|
fThemeList->RemoveItem(item);
|
|
|
|
delete item;
|
|
|
|
//err = tman->ApplyTheme(theme);
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2008-10-01 07:37:33 +04:00
|
|
|
|
|
|
|
status_t
|
|
|
|
ThemeInterfaceView::AddScreenshot()
|
2008-01-11 21:06:15 +03:00
|
|
|
{
|
|
|
|
status_t err;
|
|
|
|
ThemeManager* tman = GetThemeManager();
|
|
|
|
int32 id;
|
|
|
|
ThemeItem *item;
|
|
|
|
BMessage theme;
|
|
|
|
// find selected theme
|
|
|
|
id = fThemeList->CurrentSelection(0);
|
|
|
|
if (id < 0)
|
|
|
|
return B_OK;
|
|
|
|
item = dynamic_cast<ThemeItem *>(fThemeList->ItemAt(id));
|
|
|
|
if (!item)
|
|
|
|
return AError(__FUNCTION__, ENOENT);
|
|
|
|
id = item->ThemeId();
|
|
|
|
if (id < 0)
|
|
|
|
return AError(__FUNCTION__, ENOENT);
|
|
|
|
// then apply
|
|
|
|
err = tman->MakeThemeScreenShot(id);
|
|
|
|
if (err)
|
|
|
|
return AError(__FUNCTION__, err);
|
|
|
|
err = tman->SaveTheme(id);
|
|
|
|
if (err)
|
|
|
|
return AError(__FUNCTION__, err);
|
|
|
|
ThemeSelected(); // force reload of description for selected theme.
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2008-10-01 07:37:33 +04:00
|
|
|
|
|
|
|
status_t
|
|
|
|
ThemeInterfaceView::ThemeSelected()
|
2008-01-11 21:06:15 +03:00
|
|
|
{
|
|
|
|
status_t err;
|
|
|
|
ThemeManager* tman = GetThemeManager();
|
|
|
|
int32 id;
|
|
|
|
ThemeItem *item;
|
|
|
|
BString desc;
|
|
|
|
BBitmap *sshot = NULL;
|
|
|
|
// find selected theme
|
|
|
|
id = fThemeList->CurrentSelection(0);
|
|
|
|
if (id < 0)
|
|
|
|
{
|
|
|
|
fScreenshotPane->ClearViewBitmap();
|
|
|
|
fScreenshotPane->Invalidate(fScreenshotPane->Bounds());
|
|
|
|
|
|
|
|
HideScreenshotPane(false);
|
|
|
|
while(true == fScreenshotNone->IsHidden())
|
|
|
|
fScreenshotNone->Show();
|
|
|
|
|
|
|
|
fScreenshotNone->SetText(_T("No Theme selected"));
|
|
|
|
return ENOENT;
|
|
|
|
}
|
|
|
|
|
|
|
|
item = dynamic_cast<ThemeItem *>(fThemeList->ItemAt(id));
|
|
|
|
if (!item)
|
|
|
|
return ENOENT;
|
|
|
|
id = item->ThemeId();
|
|
|
|
if (id < 0)
|
|
|
|
return ENOENT;
|
|
|
|
// then apply
|
|
|
|
|
|
|
|
err = tman->ThemeScreenShot(id, &sshot);
|
|
|
|
if (err)
|
|
|
|
sshot = NULL;
|
|
|
|
if (sshot == NULL)
|
|
|
|
{
|
|
|
|
SetScreenshot(NULL);
|
|
|
|
fprintf(stderr, "ThemeManager: no screenshot; error 0x%08lx\n", err);
|
|
|
|
|
|
|
|
HideScreenshotPane(false);
|
|
|
|
while(true == fScreenshotNone->IsHidden())
|
|
|
|
fScreenshotNone->Show();
|
|
|
|
|
|
|
|
fScreenshotNone->SetText(_T("No Screenshot"));
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
SetScreenshot(sshot);
|
|
|
|
while(false == fScreenshotNone->IsHidden())
|
|
|
|
fScreenshotNone->Hide();
|
|
|
|
|
|
|
|
//err = tman->ApplyTheme(theme);
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2008-10-01 07:37:33 +04:00
|
|
|
|
|
|
|
void
|
|
|
|
ThemeInterfaceView::SetIsRevertable()
|
2008-01-11 21:06:15 +03:00
|
|
|
{
|
|
|
|
BMessenger msgr(Parent());
|
|
|
|
msgr.SendMessage(B_PREF_APP_ENABLE_REVERT);
|
|
|
|
}
|
|
|
|
|
2008-10-01 07:37:33 +04:00
|
|
|
|
2008-01-11 21:06:15 +03:00
|
|
|
// PRIVATE: in libzeta for now.
|
|
|
|
extern status_t ScaleBitmap(const BBitmap& inBitmap, BBitmap& outBitmap);
|
|
|
|
|
2008-10-01 07:37:33 +04:00
|
|
|
|
|
|
|
void
|
|
|
|
ThemeInterfaceView::SetScreenshot(BBitmap *shot)
|
2008-01-11 21:06:15 +03:00
|
|
|
{
|
|
|
|
// no screenshotpanel
|
|
|
|
if(NULL == fScreenshotPane)
|
|
|
|
return;
|
|
|
|
|
|
|
|
fScreenshotPane->ClearViewBitmap();
|
|
|
|
if (shot)
|
|
|
|
{
|
|
|
|
BBitmap scaled(fScreenshotPane->Bounds(), B_RGB32);
|
2008-01-12 04:11:45 +03:00
|
|
|
status_t err = ENOSYS;
|
|
|
|
#ifdef B_ZETA_VERSION
|
|
|
|
err = ScaleBitmap(*shot, scaled);
|
|
|
|
#endif
|
|
|
|
if( err == B_OK )
|
2008-01-11 21:06:15 +03:00
|
|
|
{
|
|
|
|
fScreenshotPane->SetViewBitmap(&scaled);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
fScreenshotPane->SetViewBitmap(shot, shot->Bounds(), fScreenshotPane->Bounds());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fScreenshotPane->Invalidate(fScreenshotPane->Bounds());
|
|
|
|
fHasScreenshot = (shot != NULL);
|
|
|
|
|
|
|
|
if (shot)
|
|
|
|
delete shot;
|
|
|
|
}
|
|
|
|
|
2008-10-01 07:37:33 +04:00
|
|
|
|
|
|
|
status_t
|
|
|
|
ThemeInterfaceView::AError(const char *func, status_t err)
|
2008-01-11 21:06:15 +03:00
|
|
|
{
|
|
|
|
BAlert *alert;
|
|
|
|
BString msg;
|
|
|
|
char *str = strerror(err);
|
|
|
|
msg << "Error in " << func << "() : " << str;
|
|
|
|
alert = new BAlert("error", msg.String(), _T("Ok"));
|
|
|
|
alert->Go();
|
|
|
|
return err; /* pass thru */
|
|
|
|
}
|
|
|
|
|