|
From: CVS C. to T. <the...@li...> - 2010-11-02 21:31:28
|
Revision: 555
http://themis.svn.sourceforge.net/themis/?rev=555&view=rev
Author: mark_hellegers
Date: 2010-11-02 21:31:21 +0000 (Tue, 02 Nov 2010)
Log Message:
-----------
- Implemented preferences for the HTML parser.
Modified Paths:
--------------
trunk/themis/modules/HTMLParser/HTMLParser.cpp
trunk/themis/modules/HTMLParser/HTMLParser.h
Added Paths:
-----------
trunk/themis/modules/HTMLParser/HTMLParserPrefsView.cpp
trunk/themis/modules/HTMLParser/HTMLParserPrefsView.hpp
Modified: trunk/themis/modules/HTMLParser/HTMLParser.cpp
===================================================================
--- trunk/themis/modules/HTMLParser/HTMLParser.cpp 2010-11-02 21:30:57 UTC (rev 554)
+++ trunk/themis/modules/HTMLParser/HTMLParser.cpp 2010-11-02 21:31:21 UTC (rev 555)
@@ -14,6 +14,7 @@
// Be headers
#include <Message.h>
#include <DataIO.h>
+#include <storage/Directory.h>
// HTMLParser headers
#include "HTMLParser.h"
@@ -28,6 +29,7 @@
#include "SGMLText.hpp"
#include "TSchema.hpp"
#include "SGMLScanner.hpp"
+#include "HTMLParserPrefsView.hpp"
HTMLParser * parser;
BMessage ** appSettings_p;
@@ -86,6 +88,18 @@
// We only support one mimetype at the momemt.
mMimeTypes.push_back("text/html");
+ // Check the settings...
+ if(!appSettings->HasString(kPrefsDTDDirectory)) {
+ BString dir;
+ AppSettings->FindString(kPrefsSettingsDirectory, &dir);
+ dir.Append("/dtd");
+ AppSettings->AddString(kPrefsDTDDirectory, dir.String());
+ BEntry ent(dir.String(), true);
+ if (!ent.Exists()) {
+ create_directory(dir.String(), 0555);
+ }
+ }
+
}
HTMLParser :: ~HTMLParser() {
@@ -267,7 +281,32 @@
void HTMLParser :: MessageReceived(BMessage * aMessage) {
- BHandler::MessageReceived(aMessage);
+ switch (aMessage->what) {
+ case DTD_CHANGED_PARSER: {
+ Debug("Request to change parser", PlugID());
+ BString dtdString;
+ aMessage->FindString("DTDFileString", &dtdString);
+ appSettings->ReplaceString(kPrefsActiveDTDPath, dtdString.String());
+ mActiveDTDPath = dtdString.String();
+ if (mActiveDTDPath != "") {
+ string dtdLoad = "Loading new DTD: ";
+ dtdLoad += mActiveDTDPath;
+ Debug(dtdLoad.c_str(), PlugID());
+ TSchemaPtr schema = TSchemaPtr(new TSchema());
+ schema->setup();
+
+ SGMLScanner * scanner = new SGMLScanner();
+ mParser = new SGMLParser(scanner, schema);
+ mParser->loadSchema(mActiveDTDPath.c_str());
+ Debug("New DTD loaded", PlugID());
+ }
+ break;
+ }
+ default: {
+ BHandler::MessageReceived(aMessage);
+ }
+ }
+
}
@@ -339,23 +378,6 @@
}
break;
}
- case DTD_CHANGED_PARSER: {
- Debug("Request to change parser", PlugID());
- mActiveDTDPath = GetDTDPathFromSettings();
- if (mActiveDTDPath != "") {
- string dtdLoad = "Loading new DTD: ";
- dtdLoad += mActiveDTDPath;
- Debug(dtdLoad.c_str(), PlugID());
- TSchemaPtr schema = TSchemaPtr(new TSchema());
- schema->setup();
-
- SGMLScanner * scanner = new SGMLScanner();
- mParser = new SGMLParser(scanner, schema);
- mParser->loadSchema(mActiveDTDPath.c_str());
- Debug("New DTD loaded", PlugID());
- }
- break;
- }
case SH_PARSE_DOC_START: {
// Not used as the message is sent directly to this parser without a mime-type.
// if (IsDocumentSupported(aMessage)) {
@@ -404,3 +426,19 @@
return TARGET_PARSER;
}
+
+char * HTMLParser :: SettingsViewLabel() {
+
+ return "HTML Parser";
+}
+
+BView * HTMLParser :: SettingsView(BRect aFrame) {
+
+ HTMLParserPrefsView * view = new HTMLParserPrefsView(
+ aFrame,
+ "HTML Parser",
+ this);
+
+ return view;
+
+}
Modified: trunk/themis/modules/HTMLParser/HTMLParser.h
===================================================================
--- trunk/themis/modules/HTMLParser/HTMLParser.h 2010-11-02 21:30:57 UTC (rev 554)
+++ trunk/themis/modules/HTMLParser/HTMLParser.h 2010-11-02 21:31:21 UTC (rev 555)
@@ -86,6 +86,8 @@
status_t BroadcastReply(BMessage * aMessage);
uint32 BroadcastTarget();
int32 Type();
+ char * SettingsViewLabel();
+ BView * SettingsView(BRect aFrame);
};
Added: trunk/themis/modules/HTMLParser/HTMLParserPrefsView.cpp
===================================================================
--- trunk/themis/modules/HTMLParser/HTMLParserPrefsView.cpp (rev 0)
+++ trunk/themis/modules/HTMLParser/HTMLParserPrefsView.cpp 2010-11-02 21:31:21 UTC (rev 555)
@@ -0,0 +1,159 @@
+/*
+ Copyright (c) 2010 Mark Hellegers. All Rights Reserved.
+
+ Permission is hereby granted, free of charge, to any person
+ obtaining a copy of this software and associated documentation
+ files (the "Software"), to deal in the Software without
+ restriction, including without limitation the rights to use,
+ copy, modify, merge, publish, distribute, sublicense, and/or
+ sell copies of the Software, and to permit persons to whom
+ the Software is furnished to do so, subject to the following
+ conditions:
+
+ The above copyright notice and this permission notice
+ shall be included in all copies or substantial portions
+ of the Software.
+
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
+ KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
+ WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
+ PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS
+ OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
+ OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
+ OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+ Original Author: Mark Hellegers (ma...@fi...)
+ Project Start Date: October 18, 2000
+ Class Start Date: October 31, 2010
+*/
+
+/* HTMLParserPrefsView implementation
+ See HTMLParserPrefsView.hpp for more information
+*/
+
+// Standard C headers
+#include <stdio.h>
+
+// BeOS headers
+#include <interface/Window.h>
+#include <interface/Box.h>
+#include <interface/PopUpMenu.h>
+#include <interface/MenuItem.h>
+#include <interface/MenuField.h>
+#include <storage/Directory.h>
+#include <storage/Entry.h>
+#include <storage/Path.h>
+
+// Themis headers
+#include "commondefs.h"
+#include "PrefsDefs.h"
+#include "plugclass.h"
+
+
+// HTMLParser headers
+#include "HTMLParserPrefsView.hpp"
+
+HTMLParserPrefsView :: HTMLParserPrefsView(BRect aFrame,
+ const char* aName,
+ BHandler * aPlugin)
+ : BasePrefsView(aFrame,
+ aName) {
+
+ mPlugin = aPlugin;
+
+ /* DTD selection */
+ mPopUpMenu = new BPopUpMenu(
+ "No DTD selected or available!",
+ true,
+ true,
+ B_ITEMS_IN_COLUMN);
+
+ /* find a DTD */
+ AppSettings->FindString(kPrefsSettingsDirectory, &mDTDDir);
+ mDTDDir.Append("/dtd/");
+ printf("DTD dir: %s\n", mDTDDir.String());
+
+ BDirectory dir(mDTDDir.String());
+ if(dir.InitCheck() != B_OK) {
+ printf("DTD directory (%s) not found!\n", mDTDDir.String());
+ printf("Setting DTDToUsePath to \"none\"\n");
+ AppSettings->AddString(kPrefsActiveDTDPath, kNoDTDFoundString);
+ }
+ else {
+ BString activeDTD;
+ AppSettings->FindString(kPrefsActiveDTDPath, &activeDTD);
+
+ BEntry entry;
+ while(dir.GetNextEntry(&entry, false) != B_ENTRY_NOT_FOUND) {
+ BPath path;
+ entry.GetPath(&path);
+ char name[B_FILE_NAME_LENGTH];
+ entry.GetName(name);
+
+ BString nstring(name);
+ printf("----------------\n");
+ printf("found file: %s\n", nstring.String());
+ if(nstring.IFindFirst("DTD", nstring.Length() - 3) != B_ERROR) {
+ printf("found DTD file: %s\n", nstring.String());
+
+ /* add the file to the popupmenu */
+ BMessage* msg = new BMessage(DTD_CHANGED_PARSER);
+ msg->AddString("DTDFileString", path.Path());
+ BMenuItem* item = new BMenuItem(name, msg, 0, 0);
+ item->SetTarget(mPlugin);
+ mPopUpMenu->AddItem(item);
+
+ // if the path of the current file equals the one of the settings,
+ // mark the item
+ if(strcmp(activeDTD.String(), path.Path()) == 0) {
+ printf("DTD from settings found -> SetMarked( true )\n");
+ (mPopUpMenu->ItemAt(mPopUpMenu->CountItems() - 1))->SetMarked(true);
+ }
+ }
+ } // while
+
+ }
+ // end: find a DTD
+ BRect rect = mMainBox->Bounds();
+ rect.InsetBy(kItemSpacing, kItemSpacing);
+ rect.top += kBBoxExtraInset;
+
+ BMenuField* dtdmenufield = new BMenuField(
+ rect,
+ "DTDFIELD", "Document Type Definition:",
+ mPopUpMenu,
+ true,
+ B_FOLLOW_TOP,
+ B_WILL_DRAW);
+ dtdmenufield->SetDivider(be_plain_font->StringWidth("Document Type Definition:") + kItemSpacing);
+ mMainBox->AddChild(dtdmenufield);
+
+}
+
+void HTMLParserPrefsView :: AttachedToWindow() {
+
+ // if we found some DTDs, but still no DTD is saved in the prefs,
+ // or no DTD is selected:
+ // set the last found DTD in the prefs. we save it to the prefs,
+ // because the user might not reselect a DTD in the list, which
+ // would save the DTD.
+ BMessage msg(DTD_CHANGED_PARSER);
+ BMessenger msgr(mPlugin);
+ if(mPopUpMenu->CountItems() > 0) {
+ if(mPopUpMenu->FindMarked() == NULL) {
+ printf("no marked item found\n");
+ BMenuItem* item = mPopUpMenu->ItemAt(mPopUpMenu->CountItems() - 1);
+ item->SetMarked(true);
+ // as we cannot invoke the item here, send the DTD_SELECTED message here
+ BString dtdstring(mDTDDir.String());
+ dtdstring.Append(item->Label());
+ msg.AddString("DTDFileString", dtdstring.String());
+ msgr.SendMessage(&msg);
+ }
+ }
+ else {
+ msg.AddString("DTDFileString", kNoDTDFoundString);
+ msgr.SendMessage(&msg);
+ }
+}
Added: trunk/themis/modules/HTMLParser/HTMLParserPrefsView.hpp
===================================================================
--- trunk/themis/modules/HTMLParser/HTMLParserPrefsView.hpp (rev 0)
+++ trunk/themis/modules/HTMLParser/HTMLParserPrefsView.hpp 2010-11-02 21:31:21 UTC (rev 555)
@@ -0,0 +1,73 @@
+/*
+ Copyright (c) 2010 Mark Hellegers. All Rights Reserved.
+
+ Permission is hereby granted, free of charge, to any person
+ obtaining a copy of this software and associated documentation
+ files (the "Software"), to deal in the Software without
+ restriction, including without limitation the rights to use,
+ copy, modify, merge, publish, distribute, sublicense, and/or
+ sell copies of the Software, and to permit persons to whom
+ the Software is furnished to do so, subject to the following
+ conditions:
+
+ The above copyright notice and this permission notice
+ shall be included in all copies or substantial portions
+ of the Software.
+
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
+ KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
+ WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
+ PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS
+ OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
+ OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
+ OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+ Original Author: Mark Hellegers (ma...@fi...)
+ Project Start Date: October 18, 2000
+ Class Start Date: October 31, 2010
+*/
+
+/* HTMLParserPrefsView
+ Contains the preferences view for the HTML parser addon.
+
+ Mark Hellegers (ma...@fi...)
+ 31-10-2010
+*/
+
+#ifndef HTMLPARSERPREFSVIEW_HPP
+#define HTMLPARSERPREFSVIEW_HPP
+
+// BeOS headers
+#include <String.h>
+
+// Themis headers
+#include "BasePrefsView.hpp"
+
+// Declarations used
+class BPopUpMenu;
+class BHandler;
+
+/// Class to view the preferences of the HTML parser addon.
+
+/**
+ This class is a view of the preferences of the HTML parser addon.
+*/
+
+class HTMLParserPrefsView : public BasePrefsView {
+
+ private:
+ BPopUpMenu * mPopUpMenu;
+ BString mDTDDir;
+ BHandler * mPlugin;
+
+ public:
+ HTMLParserPrefsView(BRect aFrame,
+ const char* aName,
+ BHandler * aPlugin);
+ virtual void AttachedToWindow();
+
+};
+
+#endif
+
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|