1bc87894eSGerasim Troeglazov /*
2bc87894eSGerasim Troeglazov * Copyright 2013, Gerasim Troeglazov, 3dEyes@gmail.com. All rights reserved.
3bc87894eSGerasim Troeglazov * Distributed under the terms of the MIT License.
4bc87894eSGerasim Troeglazov */
5bc87894eSGerasim Troeglazov
6bc87894eSGerasim Troeglazov #include "ConfigView.h"
7bc87894eSGerasim Troeglazov
8c4696b30SJérôme Duval #include <Catalog.h>
9c2751c41SJanus #include <LayoutBuilder.h>
10a47ae0d0SGerasim Troeglazov #include <MenuItem.h>
11c4696b30SJérôme Duval #include <PopUpMenu.h>
12c4696b30SJérôme Duval #include <StringView.h>
13bc87894eSGerasim Troeglazov
14bc87894eSGerasim Troeglazov #include <stdio.h>
15bc87894eSGerasim Troeglazov
16a47ae0d0SGerasim Troeglazov #include "PSDLoader.h"
17c4696b30SJérôme Duval #include "PSDTranslator.h"
18c4696b30SJérôme Duval
19c4696b30SJérôme Duval #undef B_TRANSLATION_CONTEXT
20c4696b30SJérôme Duval #define B_TRANSLATION_CONTEXT "PSDConfig"
21a47ae0d0SGerasim Troeglazov
22bc87894eSGerasim Troeglazov
ConfigView(TranslatorSettings * settings)23bc87894eSGerasim Troeglazov ConfigView::ConfigView(TranslatorSettings *settings)
24c4696b30SJérôme Duval : BGroupView(B_TRANSLATE("PSDTranslator Settings"), B_VERTICAL, 0)
25bc87894eSGerasim Troeglazov {
26bc87894eSGerasim Troeglazov fSettings = settings;
27bc87894eSGerasim Troeglazov
286d7acad2SGerasim Troeglazov BPopUpMenu* compressionPopupMenu = new BPopUpMenu("popup_compression");
29a47ae0d0SGerasim Troeglazov
30a47ae0d0SGerasim Troeglazov uint32 currentCompression =
31a47ae0d0SGerasim Troeglazov fSettings->SetGetInt32(PSD_SETTING_COMPRESSION);
32a47ae0d0SGerasim Troeglazov
33c4696b30SJérôme Duval _AddItemToMenu(compressionPopupMenu, B_TRANSLATE("Uncompressed"),
346d7acad2SGerasim Troeglazov MSG_COMPRESSION_CHANGED, PSD_COMPRESSED_RAW, currentCompression);
35c4696b30SJérôme Duval _AddItemToMenu(compressionPopupMenu, B_TRANSLATE("RLE"),
366d7acad2SGerasim Troeglazov MSG_COMPRESSION_CHANGED, PSD_COMPRESSED_RLE, currentCompression);
37a47ae0d0SGerasim Troeglazov
38a47ae0d0SGerasim Troeglazov fCompressionField = new BMenuField("compression",
39c4696b30SJérôme Duval B_TRANSLATE("Compression: "), compressionPopupMenu);
407bfb4a1eSJanus fCompressionField->SetAlignment(B_ALIGN_RIGHT);
416d7acad2SGerasim Troeglazov
426d7acad2SGerasim Troeglazov BPopUpMenu* versionPopupMenu = new BPopUpMenu("popup_version");
436d7acad2SGerasim Troeglazov
446d7acad2SGerasim Troeglazov uint32 currentVersion =
456d7acad2SGerasim Troeglazov fSettings->SetGetInt32(PSD_SETTING_VERSION);
466d7acad2SGerasim Troeglazov
47c4696b30SJérôme Duval _AddItemToMenu(versionPopupMenu,
483292b902SHumdinger B_TRANSLATE("Photoshop Document (PSD file)"), MSG_VERSION_CHANGED,
49c4696b30SJérôme Duval PSD_FILE, currentVersion);
50c4696b30SJérôme Duval _AddItemToMenu(versionPopupMenu,
513292b902SHumdinger B_TRANSLATE("Photoshop Big Document (PSB file)"), MSG_VERSION_CHANGED,
52c4696b30SJérôme Duval PSB_FILE, currentVersion);
536d7acad2SGerasim Troeglazov
546d7acad2SGerasim Troeglazov fVersionField = new BMenuField("version",
55c4696b30SJérôme Duval B_TRANSLATE("Format: "), versionPopupMenu);
567bfb4a1eSJanus fVersionField->SetAlignment(B_ALIGN_RIGHT);
57a47ae0d0SGerasim Troeglazov
58c2751c41SJanus BStringView *titleView = new BStringView("title",
59c4696b30SJérôme Duval B_TRANSLATE("Photoshop image translator"));
60c2751c41SJanus titleView->SetFont(be_bold_font);
61bc87894eSGerasim Troeglazov
62bc87894eSGerasim Troeglazov char version[256];
63c4696b30SJérôme Duval sprintf(version, B_TRANSLATE("Version %d.%d.%d, %s"),
64bc87894eSGerasim Troeglazov int(B_TRANSLATION_MAJOR_VERSION(PSD_TRANSLATOR_VERSION)),
65bc87894eSGerasim Troeglazov int(B_TRANSLATION_MINOR_VERSION(PSD_TRANSLATOR_VERSION)),
66bc87894eSGerasim Troeglazov int(B_TRANSLATION_REVISION_VERSION(PSD_TRANSLATOR_VERSION)),
67bc87894eSGerasim Troeglazov __DATE__);
68bc87894eSGerasim Troeglazov
69c2751c41SJanus BStringView *versionView = new BStringView("version", version);
70c2751c41SJanus BStringView *copyrightView = new BStringView("copyright",
71bc87894eSGerasim Troeglazov B_UTF8_COPYRIGHT "2005-2013 Haiku Inc.");
72c2751c41SJanus BStringView *copyright2View = new BStringView("my_copyright",
73bc87894eSGerasim Troeglazov B_UTF8_COPYRIGHT "2012-2013 Gerasim Troeglazov <3dEyes@gmail.com>");
74bc87894eSGerasim Troeglazov
75c2751c41SJanus BLayoutBuilder::Group<>(this, B_VERTICAL, 0)
76c2751c41SJanus .SetInsets(B_USE_DEFAULT_SPACING)
77c2751c41SJanus .Add(titleView)
78c2751c41SJanus .Add(versionView)
79c2751c41SJanus .Add(copyrightView)
80c2751c41SJanus .AddGlue()
817bfb4a1eSJanus .AddGrid(10.0f, 5.0f)
827bfb4a1eSJanus .Add(fVersionField->CreateLabelLayoutItem(), 0, 0)
83*d712965dSJohn Scipione .AddGroup(B_HORIZONTAL, 0.0f, 1, 0)
84*d712965dSJohn Scipione .Add(fVersionField->CreateMenuBarLayoutItem(), 0.0f)
85*d712965dSJohn Scipione .AddGlue()
86*d712965dSJohn Scipione .End()
877bfb4a1eSJanus .Add(fCompressionField->CreateLabelLayoutItem(), 0, 1)
88*d712965dSJohn Scipione .AddGroup(B_HORIZONTAL, 0.0f, 1, 1)
89*d712965dSJohn Scipione .Add(fCompressionField->CreateMenuBarLayoutItem(), 0.0f)
90*d712965dSJohn Scipione .AddGlue()
91*d712965dSJohn Scipione .End()
927bfb4a1eSJanus .End()
93c2751c41SJanus .AddGlue()
94c2751c41SJanus .Add(copyright2View);
95bc87894eSGerasim Troeglazov }
96bc87894eSGerasim Troeglazov
97bc87894eSGerasim Troeglazov
~ConfigView()98bc87894eSGerasim Troeglazov ConfigView::~ConfigView()
99bc87894eSGerasim Troeglazov {
100bc87894eSGerasim Troeglazov fSettings->Release();
101bc87894eSGerasim Troeglazov }
102bc87894eSGerasim Troeglazov
103bc87894eSGerasim Troeglazov
104bc87894eSGerasim Troeglazov void
AllAttached()105bc87894eSGerasim Troeglazov ConfigView::AllAttached()
106bc87894eSGerasim Troeglazov {
107a47ae0d0SGerasim Troeglazov fCompressionField->Menu()->SetTargetForItems(this);
1086d7acad2SGerasim Troeglazov fVersionField->Menu()->SetTargetForItems(this);
109bc87894eSGerasim Troeglazov }
110bc87894eSGerasim Troeglazov
111bc87894eSGerasim Troeglazov
112bc87894eSGerasim Troeglazov void
MessageReceived(BMessage * message)113bc87894eSGerasim Troeglazov ConfigView::MessageReceived(BMessage* message)
114bc87894eSGerasim Troeglazov {
115bc87894eSGerasim Troeglazov switch (message->what) {
116a47ae0d0SGerasim Troeglazov case MSG_COMPRESSION_CHANGED: {
117a47ae0d0SGerasim Troeglazov int32 value;
118a47ae0d0SGerasim Troeglazov if (message->FindInt32("value", &value) >= B_OK) {
119a47ae0d0SGerasim Troeglazov fSettings->SetGetInt32(PSD_SETTING_COMPRESSION, &value);
120a47ae0d0SGerasim Troeglazov fSettings->SaveSettings();
121a47ae0d0SGerasim Troeglazov }
122a47ae0d0SGerasim Troeglazov break;
123a47ae0d0SGerasim Troeglazov }
1246d7acad2SGerasim Troeglazov case MSG_VERSION_CHANGED: {
1256d7acad2SGerasim Troeglazov int32 value;
1266d7acad2SGerasim Troeglazov if (message->FindInt32("value", &value) >= B_OK) {
1276d7acad2SGerasim Troeglazov fSettings->SetGetInt32(PSD_SETTING_VERSION, &value);
1286d7acad2SGerasim Troeglazov fSettings->SaveSettings();
1296d7acad2SGerasim Troeglazov }
1306d7acad2SGerasim Troeglazov break;
1316d7acad2SGerasim Troeglazov }
132bc87894eSGerasim Troeglazov default:
133bc87894eSGerasim Troeglazov BView::MessageReceived(message);
134bc87894eSGerasim Troeglazov }
135bc87894eSGerasim Troeglazov }
136a47ae0d0SGerasim Troeglazov
137a47ae0d0SGerasim Troeglazov
138a47ae0d0SGerasim Troeglazov void
_AddItemToMenu(BMenu * menu,const char * label,uint32 mess,uint32 value,uint32 current_value)139a47ae0d0SGerasim Troeglazov ConfigView::_AddItemToMenu(BMenu* menu, const char* label,
1406d7acad2SGerasim Troeglazov uint32 mess, uint32 value, uint32 current_value)
141a47ae0d0SGerasim Troeglazov {
1426d7acad2SGerasim Troeglazov BMessage* message = new BMessage(mess);
143a47ae0d0SGerasim Troeglazov message->AddInt32("value", value);
144a47ae0d0SGerasim Troeglazov BMenuItem* item = new BMenuItem(label, message);
145a47ae0d0SGerasim Troeglazov item->SetMarked(value == current_value);
146a47ae0d0SGerasim Troeglazov menu->AddItem(item);
147a47ae0d0SGerasim Troeglazov }
148