-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathSyncConflictDialog.cpp
More file actions
126 lines (109 loc) · 4.04 KB
/
SyncConflictDialog.cpp
File metadata and controls
126 lines (109 loc) · 4.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
/**
* @file SyncConflictDialog.cpp
* @brief Implementation of metadata conflict resolution dialog.
*/
#include "SyncConflictDialog.h"
#include "Debug.h"
#include "Messages.h"
#include <Catalog.h>
#include <LayoutBuilder.h>
#include <SeparatorView.h>
#undef B_TRANSLATION_CONTEXT
#define B_TRANSLATION_CONTEXT "SyncConflictDialog"
SyncConflictDialog::SyncConflictDialog(BMessenger target,
const BString &filePath,
const TagData &tags, const TagData &bfs,
int32 index, int32 total)
: BWindow(BRect(0, 0, 450, 350), B_TRANSLATE("Metadata Conflict"),
B_MODAL_WINDOW,
B_NOT_RESIZABLE | B_NOT_ZOOMABLE | B_AUTO_UPDATE_SIZE_LIMITS |
B_CLOSE_ON_ESCAPE),
fTarget(target), fFilePath(filePath), fTags(tags), fBfs(bfs),
fIndex(index), fTotal(total), fUseTags(nullptr), fUseBfs(nullptr) {
BuildLayout();
CenterOnScreen();
}
void SyncConflictDialog::BuildLayout() {
BString fileInfo;
fileInfo.SetToFormat(B_TRANSLATE("File %ld of %ld"), (long)(fIndex + 1),
(long)fTotal);
BString tagsInfo;
tagsInfo << B_TRANSLATE("Title: ") << fTags.title << "\n"
<< B_TRANSLATE("Artist: ") << fTags.artist << "\n"
<< B_TRANSLATE("Album: ") << fTags.album;
BString bfsInfo;
bfsInfo << B_TRANSLATE("Title: ") << fBfs.title << "\n"
<< B_TRANSLATE("Artist: ") << fBfs.artist << "\n"
<< B_TRANSLATE("Album: ") << fBfs.album;
fUseTags = new BRadioButton("useTags", B_TRANSLATE("Use Tags"), nullptr);
fUseBfs = new BRadioButton("useBfs", B_TRANSLATE("Use BFS"), nullptr);
fUseTags->SetValue(B_CONTROL_ON);
BButton *cancelBtn = new BButton("cancel", B_TRANSLATE("Cancel"),
new BMessage(MSG_SYNC_CONFLICT_SKIP));
BButton *applyBtn = new BButton("apply", B_TRANSLATE("Apply"),
new BMessage(MSG_SYNC_CONFLICT_OK));
BButton *allBtn = new BButton("all", B_TRANSLATE("Apply to All"),
new BMessage(MSG_SYNC_CONFLICT_ALL));
applyBtn->MakeDefault(true);
fFileLabel = new BStringView("fileLabel", fileInfo);
BLayoutBuilder::Group<>(this, B_VERTICAL, B_USE_DEFAULT_SPACING)
.SetInsets(B_USE_WINDOW_INSETS)
.Add(fFileLabel)
.Add(new BStringView("pathLabel", fFilePath))
.Add(new BSeparatorView(B_HORIZONTAL))
.AddGroup(B_HORIZONTAL)
.AddGroup(B_VERTICAL)
.Add(new BStringView("tagsLabel", B_TRANSLATE("Tags")))
.Add(new BStringView("tagsInfo", tagsInfo))
.Add(fUseTags)
.End()
.Add(new BSeparatorView(B_VERTICAL))
.AddGroup(B_VERTICAL)
.Add(new BStringView("bfsLabel", B_TRANSLATE("BFS Attributes")))
.Add(new BStringView("bfsInfo", bfsInfo))
.Add(fUseBfs)
.End()
.End()
.Add(new BSeparatorView(B_HORIZONTAL))
.AddGroup(B_HORIZONTAL)
.Add(cancelBtn)
.AddGlue()
.Add(allBtn)
.Add(applyBtn)
.End()
.End();
}
void SyncConflictDialog::MessageReceived(BMessage *msg) {
switch (msg->what) {
case MSG_SYNC_CONFLICT_SKIP:
case MSG_SYNC_CONFLICT_OK:
case MSG_SYNC_CONFLICT_ALBUM:
case MSG_SYNC_CONFLICT_ALL:
SendChoice(msg->what);
break;
default:
BWindow::MessageReceived(msg);
}
}
void SyncConflictDialog::SendChoice(uint32 what) {
BMessage reply(what);
reply.AddString("path", fFilePath);
reply.AddInt32("index", fIndex);
reply.AddInt32("total", fTotal);
reply.AddBool("useTags", fUseTags ? fUseTags->Value() == B_CONTROL_ON : true);
fTarget.SendMessage(&reply);
PostMessage(B_QUIT_REQUESTED);
}
void SyncConflictDialog::UpdateTotal(int32 newTotal) {
if (Lock()) {
fTotal = newTotal;
if (fFileLabel) {
BString fileInfo;
fileInfo.SetToFormat(B_TRANSLATE("File %ld of %ld"), (long)(fIndex + 1),
(long)fTotal);
fFileLabel->SetText(fileInfo.String());
DEBUG_PRINT("[SyncConflictDialog] UpdateTotal: %s\n", fileInfo.String());
}
Unlock();
}
}