2009-08-17 16:19:53 -04:00
|
|
|
/****************************************************************
|
|
|
|
* 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 "common/vmessagebox.h"
|
|
|
|
|
|
|
|
#include "AddLinksDialog.h"
|
2010-03-10 16:38:26 -05:00
|
|
|
#include "RetroShareLink.h"
|
2010-08-06 05:40:23 -04:00
|
|
|
#include <retroshare/rsrank.h>
|
2009-08-17 16:19:53 -04:00
|
|
|
|
|
|
|
/* 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 */
|
2009-08-17 18:06:48 -04:00
|
|
|
AddLinksDialog::AddLinksDialog(QString url, QWidget *parent)
|
2009-08-17 16:19:53 -04:00
|
|
|
: QDialog(parent)
|
|
|
|
{
|
|
|
|
/* Invoke the Qt Designer generated object setup routine */
|
|
|
|
ui.setupUi(this);
|
|
|
|
|
2010-05-04 20:05:36 -04:00
|
|
|
setAttribute ( Qt::WA_DeleteOnClose, true );
|
|
|
|
|
2009-08-17 16:19:53 -04:00
|
|
|
/* add button */
|
|
|
|
connect(ui.addLinkButton, SIGNAL(clicked()), this, SLOT(addLinkComment()));
|
|
|
|
connect(ui.closepushButton, SIGNAL(clicked()), this, SLOT(close()));
|
2010-02-01 19:01:17 -05:00
|
|
|
|
|
|
|
connect( ui.anonBox, SIGNAL( stateChanged ( int ) ), this, SLOT( load ( void ) ) );
|
2009-08-17 16:19:53 -04:00
|
|
|
|
2009-08-17 18:06:48 -04:00
|
|
|
ui.linkLineEdit->setText(url);
|
|
|
|
|
2010-03-10 16:38:26 -05:00
|
|
|
RetroShareLink link(url);
|
|
|
|
|
2010-07-15 07:25:34 -04:00
|
|
|
if(link.valid() && link.type() == RetroShareLink::TYPE_FILE)
|
2010-03-10 16:38:26 -05:00
|
|
|
ui.titleLineEdit->setText(link.name());
|
2009-08-17 18:06:48 -04:00
|
|
|
else
|
|
|
|
ui.titleLineEdit->setText("New File");
|
2009-08-17 17:06:55 -04:00
|
|
|
|
2010-02-01 19:01:17 -05:00
|
|
|
load();
|
|
|
|
|
2009-08-17 16:19:53 -04:00
|
|
|
/* Hide platform specific features */
|
|
|
|
#ifdef Q_WS_WIN
|
|
|
|
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
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 == ""))
|
|
|
|
{
|
2010-09-13 16:05:55 -04:00
|
|
|
QMessageBox::warning(NULL, tr("Add Link Failure"), tr("Missing Link and/or Title"), QMessageBox::Ok);
|
2009-08-17 16:19:53 -04:00
|
|
|
/* 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();
|
|
|
|
}
|
2010-02-01 19:01:17 -05:00
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
2010-03-10 16:38:26 -05:00
|
|
|
}
|