-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathAddLinksDialog.cpp
122 lines (102 loc) · 3.41 KB
/
AddLinksDialog.cpp
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
/****************************************************************
* RetroShare is distributed under the following license:
*
* Copyright (C) 2008 Robert Fernie
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
****************************************************************/
#include <gui/common/vmessagebox.h>
#include "AddLinksDialog.h"
//#include <gui/RetroShareLink.h>
#include "rsrank.h"
/* Images for context menu icons */
#define IMAGE_EXPORTFRIEND ":/images/exportpeers_16x16.png"
#define IMAGE_GREAT ":/images/filerating5.png"
#define IMAGE_GOOD ":/images/filerating4.png"
#define IMAGE_OK ":/images/filerating3.png"
#define IMAGE_SUX ":/images/filerating2.png"
#define IMAGE_BADLINK ":/images/filerating1.png"
/** Constructor */
AddLinksDialog::AddLinksDialog(QString url, QWidget *parent)
: QDialog(parent)
{
/* Invoke the Qt Designer generated object setup routine */
ui.setupUi(this);
ui.headerFrame->setHeaderImage(QPixmap(":/images/irkick.png"));
ui.headerFrame->setHeaderText(tr("Add Link to Cloud"));
setAttribute ( Qt::WA_DeleteOnClose, true );
/* add button */
connect(ui.addLinkButton, SIGNAL(clicked()), this, SLOT(addLinkComment()));
connect(ui.closepushButton, SIGNAL(clicked()), this, SLOT(close()));
connect( ui.anonBox, SIGNAL( stateChanged ( int ) ), this, SLOT( load ( void ) ) );
ui.linkLineEdit->setText(url);
// RetroShareLink link(url);
// if(link.valid() && link.type() == RetroShareLink::TYPE_FILE)
// ui.titleLineEdit->setText(link.name());
// else
ui.titleLineEdit->setText(tr("New Link"));
load();
}
int AddLinksDialog::IndexToScore(int index)
{
if ((index == -1) || (index > 4))
return 0;
int score = 2 - index;
return score;
}
void AddLinksDialog::addLinkComment()
{
/* get the title / link / comment */
QString title = ui.titleLineEdit->text();
QString link = ui.linkLineEdit->text();
QString comment = ui.linkTextEdit->toPlainText();
int32_t score = AddLinksDialog::IndexToScore(ui.scoreBox->currentIndex());
if ((link == "") || (title == ""))
{
QMessageBox::warning(NULL, tr("Add Link Failure"), tr("Missing Link and/or Title"), QMessageBox::Ok);
/* can't do anything */
return;
}
/* add it either way */
if (ui.anonBox->isChecked())
{
rsRanks->anonRankMsg("", link.toStdWString(), title.toStdWString());
}
else
{
rsRanks->newRankMsg(link.toStdWString(),
title.toStdWString(),
comment.toStdWString(), score);
}
close();
}
void AddLinksDialog::load()
{
if (ui.anonBox->isChecked())
{
/* disable comment + score */
ui.scoreBox->setEnabled(false);
ui.linkTextEdit->setEnabled(false);
/* done! */
return;
}
else
{
/* enable comment + score */
ui.scoreBox->setEnabled(true);
ui.linkTextEdit->setEnabled(true);
}
}