Barry debian version 0.18.5-1
[barry.git] / desktop / src / ConflictDlg.h
blobcaa470f2f3f24dad6044e46e5dbd19b30204260f
1 ///
2 /// \file ConflictDlg.h
3 /// The dialog used during a sync, to display conflicting
4 /// changes, and let the user decide what to do.
5 ///
7 /*
8 Copyright (C) 2010-2013, Net Direct Inc. (http://www.netdirect.ca/)
10 This program is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 2 of the License, or
13 (at your option) any later version.
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
19 See the GNU General Public License in the COPYING file at the
20 root directory of this project for more details.
23 #ifndef __BARRYDESKTOP_CONFLICTDLG_H__
24 #define __BARRYDESKTOP_CONFLICTDLG_H__
26 #include <wx/wx.h>
27 #include <vector>
28 #include <set>
29 #include "osbase.h"
30 #include "xmlmap.h"
32 class ConflictDlg : public wxDialog
34 DECLARE_EVENT_TABLE() // sets to protected:
36 public:
37 typedef std::tr1::shared_ptr<XmlNodeMap> map_ptr;
38 typedef std::tr1::shared_ptr<xmlpp::DomParser> dom_ptr;
40 struct XmlPair
42 ConflictDlg::dom_ptr dom; // never null
43 ConflictDlg::map_ptr map; // can contain null!
46 typedef std::vector<XmlPair> mapped_list;
47 typedef std::set<Glib::ustring> key_set;
49 // Stored by the caller to remember the "always" selection
50 // Pass it back into the dialog to have it automatically
51 // select for you.
52 struct AlwaysMemoryBlock
54 bool m_always;
55 long m_member_id;
56 std::string m_plugin_name;
57 std::string m_last_command;
58 std::string m_favour_plugin_name;
60 void clear()
62 m_always = false;
63 m_member_id = -1;
64 m_plugin_name.clear();
65 m_last_command.clear();
66 m_favour_plugin_name.clear();
69 AlwaysMemoryBlock()
70 : m_always(false)
71 , m_member_id(-1)
76 private:
77 // external data sources
78 const OpenSync::API &m_engine;
79 const std::vector<OpenSync::SyncChange> &m_changes;
80 std::string m_supported_commands; // a char string: "SDAIN"
81 AlwaysMemoryBlock &m_always;
83 // mapped data
84 mapped_list m_maps;
85 key_set m_differing_keys;
87 // results
88 bool m_kill_sync;
89 std::string m_command_string; // eg. "S 1"
91 // dialog sizing
92 int m_max_text_width;
94 // dialog controls
95 wxSizer *m_topsizer;
97 protected:
98 void CreateLayout();
99 void CreateSummaries(wxSizer *sizer);
100 void CreateSummary(wxSizer *sizer, size_t change_index);
101 void CreateSummaryGroup(wxSizer *sizer, size_t change_index);
102 void CreateSummaryButtons(wxSizer *sizer, size_t change_index);
103 bool IsDifferent(const XmlNodeMapping &mapping) const;
104 void AddEmptyNotice(wxSizer *sizer);
105 void AddMapping(wxSizer *sizer, XmlNodeMapping &mapping,
106 bool differing);
107 void CreateAlternateButtons(wxSizer *sizer);
109 void ParseChanges();
110 void CreateDifferingKeyNameSet();
112 public:
113 ConflictDlg(wxWindow *parent, const OpenSync::API &engine,
114 const std::string &supported_commands,
115 const std::vector<OpenSync::SyncChange> &changes,
116 AlwaysMemoryBlock &always);
117 ~ConflictDlg();
119 // data access
120 const std::string& GetCommand() const { return m_command_string; }
121 bool IsKillSync() const { return m_kill_sync; }
122 void Clear() { clear(); }
123 void clear();
125 // override, in order to force an answer
126 int ShowModal();
128 // event handlers
129 void OnShowButton(wxCommandEvent &event);
130 void OnSelectButton(wxCommandEvent &event);
131 void OnDuplicateButton(wxCommandEvent &event);
132 void OnAbortButton(wxCommandEvent &event);
133 void OnIgnoreButton(wxCommandEvent &event);
134 void OnKeepNewerButton(wxCommandEvent &event);
135 void OnKillSyncButton(wxCommandEvent &event);
136 void OnAlwaysCheckbox(wxCommandEvent &event);
139 #endif