Added BeTheme importer. Oops, missing a file :)

git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@23802 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
François Revol
2008-02-01 03:15:40 +00:00
parent 0148fb2dbc
commit cef53a50ba
6 changed files with 102 additions and 1 deletions
+2
View File
@@ -26,6 +26,7 @@ addonSources =
; ;
Application <3rdparty>Themes : Application <3rdparty>Themes :
BeThemeImporter.cpp
CompareMessages.cpp CompareMessages.cpp
DumpMessage.cpp DumpMessage.cpp
MakeScreenshot.cpp MakeScreenshot.cpp
@@ -33,6 +34,7 @@ Application <3rdparty>Themes :
TextInputAlert.cpp TextInputAlert.cpp
ThemeAddonItem.cpp ThemeAddonItem.cpp
ThemesApp.cpp ThemesApp.cpp
ThemeImporter.cpp
ThemeInterfaceView.cpp ThemeInterfaceView.cpp
ThemeItem.cpp ThemeItem.cpp
ThemeManager.cpp ThemeManager.cpp
+34
View File
@@ -494,6 +494,7 @@ void ThemeInterfaceView::_ThemeListPopulator()
{ {
status_t err; status_t err;
int32 i, count; int32 i, count;
int32 importer;
BString name; BString name;
ThemeItem *ti; ThemeItem *ti;
bool isro; bool isro;
@@ -502,9 +503,12 @@ void ThemeInterfaceView::_ThemeListPopulator()
tman->LoadThemes(); tman->LoadThemes();
count = tman->CountThemes(); count = tman->CountThemes();
LockLooper(); LockLooper();
fThemeList->MakeEmpty(); fThemeList->MakeEmpty();
UnlockLooper(); UnlockLooper();
// native themes
for (i = 0; i < count; i++) { for (i = 0; i < count; i++) {
err = tman->ThemeName(i, name); err = tman->ThemeName(i, name);
isro = tman->ThemeIsReadOnly(i); isro = tman->ThemeIsReadOnly(i);
@@ -516,6 +520,36 @@ void ThemeInterfaceView::_ThemeListPopulator()
UnlockLooper(); UnlockLooper();
} }
// 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();
}
}
// enable controls again
BControl *c; BControl *c;
LockLooper(); LockLooper();
for (i = 0; ChildAt(i); i++) { for (i = 0; ChildAt(i); i++) {
+55 -1
View File
@@ -21,9 +21,11 @@
#include <string.h> #include <string.h>
#include <stdio.h> #include <stdio.h>
#include "UITheme.h"
#include "ThemeManager.h" #include "ThemeManager.h"
#include "ThemesAddon.h" #include "ThemesAddon.h"
#include "UITheme.h" #include "ThemeImporter.h"
#include "BeThemeImporter.h"
#include "ParseMessage.h" #include "ParseMessage.h"
#include "DumpMessage.h" #include "DumpMessage.h"
@@ -54,6 +56,8 @@ ThemeManager::ThemeManager()
AddNames(fNames); AddNames(fNames);
LoadSettings(); LoadSettings();
// XXX: add more
fThemeImporters.AddItem(new BeThemeImporter());
// XXX test // XXX test
/* /*
@@ -952,6 +956,48 @@ status_t ThemeManager::LoadTheme(const char *path, BMessage **to)
return err; return err;
} }
int32 ThemeManager::CountThemeImporters()
{
FENTRY;
return fThemeImporters.CountItems();
}
const char * ThemeManager::ThemeImporterAt(int32 index)
{
FENTRY;
ThemeImporter *importer;
importer = static_cast<ThemeImporter *>(fThemeImporters.ItemAt(index));
if (!importer)
return NULL;
return importer->Name();
}
status_t ThemeManager::ImportThemesFor(int32 index, const char *path)
{
FENTRY;
status_t err;
int32 count;
BString m;
int32 i;
ThemeImporter *importer;
BMessage msg;
BMessage *theme;
importer = static_cast<ThemeImporter *>(fThemeImporters.ItemAt(index));
if (!importer)
return ENOENT;
err = importer->FetchThemes();
if (err < 0)
return err;
while ((importer->ImportNextTheme(&theme)) >= 0) {
AddTheme(theme);
}
importer->EndImports();
return B_OK;
}
bool ThemeManager::ThemeHasInfoFor(int32 id, BString &module) bool ThemeManager::ThemeHasInfoFor(int32 id, BString &module)
{ {
FENTRY; FENTRY;
@@ -1025,10 +1071,18 @@ bool ThemeManager::ThemeIsReadOnly(int32 id)
FENTRY; FENTRY;
status_t err; status_t err;
BString s; BString s;
BMessage *theme;
if (id < 0) if (id < 0)
return true; return true;
theme = (BMessage *)fThemeList.ItemAt(id);
if (!theme)
return true;
// imported themes are always RO for now
if (theme->FindString(Z_THEME_IMPORTER, &s) >= B_OK)
return true;
err = ThemeLocation(id, s); err = ThemeLocation(id, s);
if (err) if (err)
return true; return true;
+6
View File
@@ -91,6 +91,11 @@ status_t PackageTheme(BMessage &theme);
/* load from disk (zip / folder) */ /* load from disk (zip / folder) */
status_t LoadTheme(const char *path, BMessage **to=NULL); status_t LoadTheme(const char *path, BMessage **to=NULL);
/* Theme importation */
int32 CountThemeImporters();
const char *ThemeImporterAt(int32 index);
status_t ImportThemesFor(int32 index, const char *path=NULL);
/* Theme properties */ /* Theme properties */
bool ThemeHasInfoFor(int32 id, BString &module); bool ThemeHasInfoFor(int32 id, BString &module);
@@ -123,6 +128,7 @@ private:
int32 fAddonCount; int32 fAddonCount;
BList fThemeList; BList fThemeList;
BMessage fNames; /* pretty names for fields */ BMessage fNames; /* pretty names for fields */
BList fThemeImporters;
}; };
} // ns ThemeManager } // ns ThemeManager
+3
View File
@@ -1,3 +1,5 @@
#ifndef _THEMES_ADDON_H
#define _THEMES_ADDON_H
/* /*
* ThemesAddon class header * ThemesAddon class header
*/ */
@@ -95,3 +97,4 @@ extern "C" Z::ThemeManager::ThemesAddon *instantiate_themes_addon_window_decor()
using namespace Z::ThemeManager; using namespace Z::ThemeManager;
#endif /* _THEMES_ADDON_H */
+2
View File
@@ -13,6 +13,8 @@
#define Z_THEME_LOCATION "z:theme:location" #define Z_THEME_LOCATION "z:theme:location"
// identifies a module this theme has info for. // identifies a module this theme has info for.
#define Z_THEME_MODULE_TAG "z:theme:moduletag" #define Z_THEME_MODULE_TAG "z:theme:moduletag"
// if the theme is imported, where from
#define Z_THEME_IMPORTER "z:theme:importer"
// the names of the global BMessages // the names of the global BMessages
#define Z_THEME_INFO_MESSAGE "z:theme:infos" #define Z_THEME_INFO_MESSAGE "z:theme:infos"