forked from pbek/QOwnNotes
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsharedialog.cpp
More file actions
96 lines (76 loc) · 2.72 KB
/
sharedialog.cpp
File metadata and controls
96 lines (76 loc) · 2.72 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
#include "sharedialog.h"
#include <services/owncloudservice.h>
#include <utils/gui.h>
#include <utils/misc.h>
#include <QDebug>
#include "ui_sharedialog.h"
ShareDialog::ShareDialog(const Note ¬e, QWidget *parent)
: MasterDialog(parent), ui(new Ui::ShareDialog) {
ui->setupUi(this);
this->note = note;
// update the share link checkbox and link url line edit
updateDialog();
}
ShareDialog::~ShareDialog() { delete ui; }
/**
* Updates the share link checkbox and link url line edit
*/
void ShareDialog::updateDialog() {
note.refetch();
qDebug() << __func__ << " - 'note': " << note;
const QSignalBlocker blocker(ui->linkCheckBox);
Q_UNUSED(blocker)
const QSignalBlocker blocker2(ui->linkUrlLineEdit);
Q_UNUSED(blocker2)
const QSignalBlocker blocker3(ui->editCheckBox);
Q_UNUSED(blocker3)
ui->linkCheckBox->setChecked(note.isShared());
ui->linkUrlLineEdit->setVisible(note.isShared());
ui->linkUrlLineEdit->setText(note.getShareUrl());
ui->infoLabel1->setText(
Utils::Misc::replaceOwnCloudText(ui->infoLabel1->text()));
ui->linkCheckBox->setText(
Utils::Misc::replaceOwnCloudText(ui->linkCheckBox->text()));
ui->editCheckBox->setVisible(note.isShared());
ui->editCheckBox->setChecked(note.isShareEditAllowed());
}
/**
* Shares or removes the share from the current note
*/
void ShareDialog::on_linkCheckBox_toggled(bool checked) {
auto *ownCloud = OwnCloudService::instance();
const QSignalBlocker blocker(ui->linkCheckBox);
Q_UNUSED(blocker)
// the checked status will be set by the callback function updateDialog()
ui->linkCheckBox->setChecked(!checked);
if (checked) {
// share the note file
ownCloud->shareNote(note, this);
Utils::Gui::information(
this, QString(),
Utils::Misc::replaceOwnCloudText(
tr("Keep in mind that you still have to sync your "
"notes with your server by using the ownCloud "
"desktop sync tool to be able to share notes with "
"others!")),
QStringLiteral("share-sync-information"));
} else {
// remove the share
ownCloud->removeNoteShare(note, this);
}
}
void ShareDialog::on_editCheckBox_toggled(bool checked) {
auto *ownCloud = OwnCloudService::instance();
unsigned int permissions = note.getSharePermissions();
// set 2. bit
const uint8_t bit = 1;
if (checked) {
permissions |= 1UL << bit;
} else {
permissions &= ~(1UL << bit);
}
note.setSharePermissions(permissions);
note.store();
qDebug() << __func__ << " - 'permissions': " << permissions;
ownCloud->setPermissionsOnSharedNote(note, this);
}