[app] Add hotkey to invoke filter and reload transcript (bug #125)
[abstract.git] / storage / aaSaveDispatcher.cpp
blob49a7ab95d92caecc0a829b24ae0ecb1e140afebe
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim:set ts=2 sw=2 sts=2 et cindent tw=79 ft=cpp: */
3 /*
4 * Copyright (C) 2007 Sergey Yanovich <ynvich@gmail.com>
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License as
8 * published by the Free Software Foundation; either version 2 of the
9 * License, or (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
16 * You should have received a copy of the GNU General Public
17 * License along with this program; if not, write to the
18 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 * Boston, MA 02111-1307, USA.
22 #include <abstract/aacore.h>
24 #include "nsCOMPtr.h"
26 /* Unfrozen API */
28 /* Project includes */
29 #include <abstract/base/aaIEntity.h>
30 #include <abstract/base/aaIResource.h>
31 #include <abstract/base/aaIFlow.h>
32 #include <abstract/base/aaIEvent.h>
33 #include <abstract/base/aaIQuote.h>
34 #include <abstract/base/aaITransaction.h>
35 #include <abstract/base/aaIHandler.h>
36 #include <abstract/storage/aaISession.h>
37 #include "aaSaveDispatcher.h"
39 aaSaveDispatcher::aaSaveDispatcher(nsISupports *aSession)
41 void *tmp = nsnull;
42 aSession->QueryInterface(NS_GET_IID(aaISession), &tmp);
43 mParentSession = (aaISession *) tmp;
44 mParentSession->Release();
47 aaSaveDispatcher::~aaSaveDispatcher()
51 NS_IMPL_ISUPPORTS2(aaSaveDispatcher,
52 aaISaveQuery,
53 aaIHandler)
55 /* aaISaveQuery */
56 NS_IMETHODIMP
57 aaSaveDispatcher::Save(aaIDataNode *aNode, aaIDataNode *aOldNode)
59 NS_ENSURE_ARG_POINTER(aNode);
60 mOldNode = aOldNode;
61 return aNode->Accept(this);
64 /* aaIHandler */
65 #define AA_DISPATCH_ENTITY "@aasii.org/storage/save-entity;1"
66 #define AA_DISPATCH_RESOURCE "@aasii.org/storage/save-resource;1"
67 #define AA_DISPATCH_FLOW "@aasii.org/storage/save-flow;1"
68 #define AA_DISPATCH_EVENT "@aasii.org/storage/save-event;1"
69 #define AA_DISPATCH_QUOTE "@aasii.org/storage/save-quote;1"
70 #define AA_DISPATCH_TRANSACTION "@aasii.org/storage/save-transaction;1"
71 NS_IMETHODIMP
72 aaSaveDispatcher::HandleEntity(aaIEntity *aEntity)
74 return dispatch(AA_DISPATCH_ENTITY, aEntity);
77 NS_IMETHODIMP
78 aaSaveDispatcher::HandleResource(aaIResource *aResource)
80 return dispatch(AA_DISPATCH_RESOURCE, aResource);
83 NS_IMETHODIMP
84 aaSaveDispatcher::HandleFlow(aaIFlow *aFlow)
86 return dispatch(AA_DISPATCH_FLOW, aFlow);
89 NS_IMETHODIMP
90 aaSaveDispatcher::HandleFact(aaIFact *aFact)
92 return NS_ERROR_NOT_IMPLEMENTED;
95 NS_IMETHODIMP
96 aaSaveDispatcher::HandleEvent(aaIEvent *aEvent)
98 return dispatch(AA_DISPATCH_EVENT, aEvent);
101 NS_IMETHODIMP
102 aaSaveDispatcher::HandleQuote(aaIQuote *aQuote)
104 return dispatch(AA_DISPATCH_QUOTE, aQuote);
107 NS_IMETHODIMP
108 aaSaveDispatcher::HandleTransaction(aaITransaction *aTransaction)
110 return dispatch(AA_DISPATCH_TRANSACTION, aTransaction);
113 /* Private methods */
114 nsresult
115 aaSaveDispatcher::dispatch(const char *aContractID, aaIDataNode *aNode)
117 nsresult rv;
118 nsCOMPtr<nsISupports> queryPtr;
119 rv = mParentSession->CreateQuery(aContractID, getter_AddRefs(queryPtr));
120 NS_ENSURE_SUCCESS(rv, rv);
122 nsCOMPtr<aaISaveQuery> saveQuery(do_QueryInterface(queryPtr, &rv));
123 NS_ENSURE_SUCCESS(rv, rv);
125 return saveQuery->Save(aNode, mOldNode);