2 /// \file m_desktoptmpl.h
3 /// Ease of use templates for the Desktop mode class
7 Copyright (C) 2005-2009, Net Direct Inc. (http://www.netdirect.ca/)
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
18 See the GNU General Public License in the COPYING file at the
19 root directory of this project for more details.
22 #ifndef __BARRY_M_DESKTOPTMPL_H__
23 #define __BARRY_M_DESKTOPTMPL_H__
26 #include "m_desktop.h"
30 namespace Barry
{ namespace Mode
{
32 BXEXPORT
void LoadDatabase(unsigned int dbId
, Parser
&parser
);
33 BXEXPORT
void SaveDatabase(unsigned int dbId
, Builder
&builder
);
35 template <class RecordT
, class StorageT
>
36 void Desktop::LoadDatabaseByType(StorageT
&store
)
38 unsigned int dbId
= this->GetDBID( RecordT::GetDBName() );
39 Barry::RecordParser
<RecordT
, StorageT
> parser(store
);
40 this->LoadDatabase(dbId
, parser
);
43 template <class RecordT
, class StorageT
>
44 void Desktop::SaveDatabaseByType(StorageT
&store
)
46 unsigned int dbId
= this->GetDBID( RecordT::GetDBName() );
47 Barry::RecordBuilder
<RecordT
, StorageT
> build(store
);
48 SaveDatabase(dbId
, build
);
51 template <class StorageT
>
52 void Desktop::LoadDatabaseByName(const std::string
&name
, StorageT
&store
)
54 if( name
== Contact::GetDBName() )
55 LoadDatabaseByType
<Contact
>(store
);
56 else if( name
== Message::GetDBName() )
57 LoadDatabaseByType
<Message
>(store
);
58 else if( name
== Calendar::GetDBName() )
59 LoadDatabaseByType
<Calendar
>(store
);
61 throw Error("Unknown database name in LoadDatabaseByName: " + name
);
64 template <class StorageT
>
65 void Desktop::SaveDatabaseByName(const std::string
&name
, StorageT
&store
)
67 if( name
== Contact::GetDBName() )
68 SaveDatabaseByType
<Contact
>(store
);
69 else if( name
== Message::GetDBName() )
70 SaveDatabaseByType
<Message
>(store
);
71 else if( name
== Calendar::GetDBName() )
72 SaveDatabaseByType
<Calendar
>(store
);
74 throw Error("Unknown database name in SaveDatabaseByName: " + name
);
77 template <class RecordT
>
78 void Desktop::AddRecordByType(uint32_t recordId
, const RecordT
&rec
)
80 unsigned int dbId
= this->GetDBID( RecordT::GetDBName() );
81 // FIXME - I know this is a convenience template, but it still
82 // hurts making a temporary copy just to set the record ID...
83 // create a better API for this.
85 r
.SetIds(RecordT::GetDefaultRecType(), recordId
);
86 Barry::RecordFetch
<RecordT
> fetch(r
);
87 Barry::RecordBuilder
<RecordT
, Barry::RecordFetch
<RecordT
> > build(fetch
);
88 this->AddRecord(dbId
, build
);
92 }} // namespace Barry::Mode