Commit 19a4810c authored by Friedemann Kleint's avatar Friedemann Kleint
Browse files

CodePaster: Add setting for expiry.



Add a setting for expiry in days and additional setting for
PasteView dialog which can be used to override.

Change-Id: Ie45e26b5cefd8f468d2f5c47df148cce582b201e
Reviewed-by: default avatarTobias Hunger <tobias.hunger@digia.com>
parent 9528671f
......@@ -125,7 +125,7 @@ void CodePasterProtocol::list()
}
void CodePasterProtocol::paste(const QString &text,
ContentType /* ct */,
ContentType /* ct */, int /* expiryDays */,
const QString &username,
const QString &comment,
const QString &description)
......
......@@ -58,6 +58,7 @@ public:
void list();
void paste(const QString &text,
ContentType ct = Text,
int expiryDays = 1,
const QString &username = QString(),
const QString &comment = QString(),
const QString &description = QString());
......
......@@ -262,8 +262,8 @@ void CodepasterPlugin::post(QString data, const QString &mimeType)
const FileDataList diffChunks = splitDiffToFiles(data);
const int dialogResult = diffChunks.isEmpty() ?
view.show(username, QString(), QString(), data) :
view.show(username, QString(), QString(), diffChunks);
view.show(username, QString(), QString(), m_settings->expiryDays, data) :
view.show(username, QString(), QString(), m_settings->expiryDays, diffChunks);
// Save new protocol in case user changed it.
if (dialogResult == QDialog::Accepted
&& m_settings->protocol != view.protocol()) {
......
......@@ -181,7 +181,7 @@ void FileShareProtocol::list()
}
void FileShareProtocol::paste(const QString &text,
ContentType /* ct */,
ContentType /* ct */, int /* expiryDays */,
const QString &username,
const QString & /* comment */,
const QString &description)
......
......@@ -59,7 +59,7 @@ public:
virtual void fetch(const QString &id);
virtual void list();
virtual void paste(const QString &text,
ContentType ct = Text,
ContentType ct = Text, int expiryDays = 1,
const QString &username = QString(),
const QString &comment = QString(),
const QString &description = QString());
......
......@@ -43,8 +43,6 @@ enum { debug = 0 };
static const char hostUrlC[]= "http://paste.kde.org/";
static const char showPhpScriptpC[] = "show.php";
enum { expirySeconds = 86400 };
namespace CodePaster {
KdePasteProtocol::KdePasteProtocol(const NetworkAccessManagerProxyPtr &nw) :
NetworkProtocol(nw),
......@@ -97,7 +95,7 @@ static inline QByteArray pasteLanguage(Protocol::ContentType ct)
}
void KdePasteProtocol::paste(const QString &text,
ContentType ct,
ContentType ct, int expiryDays,
const QString &username,
const QString &comment,
const QString &description)
......@@ -115,7 +113,7 @@ void KdePasteProtocol::paste(const QString &text,
pasteData += "&paste_data=";
pasteData += QUrl::toPercentEncoding(fixNewLines(text));
pasteData += "&paste_expire=";
pasteData += QByteArray::number(expirySeconds);
pasteData += QByteArray::number(expiryDays * 86400);
pasteData += '&';
pasteData += pasteLanguage(ct);
......
......@@ -48,6 +48,7 @@ public:
virtual void fetch(const QString &id);
virtual void paste(const QString &text,
ContentType ct = Text,
int expiryDays = 1,
const QString &username = QString(),
const QString &comment = QString(),
const QString &description = QString());
......
......@@ -90,7 +90,7 @@ static QByteArray toTypeId(Protocol::ContentType ct)
}
void PasteBinDotCaProtocol::paste(const QString &text,
ContentType ct,
ContentType ct, int expiryDays,
const QString &username,
const QString & /* comment */,
const QString &description)
......@@ -103,7 +103,9 @@ void PasteBinDotCaProtocol::paste(const QString &text,
data += toTypeId(ct);
data += "&description=";
data += QUrl::toPercentEncoding(description);
data += "expiry=1%20day&name=";
data += "&expiry=";
data += QByteArray::number(expiryDays);
data += "%20day&name=";
data += QUrl::toPercentEncoding(username);
// fire request
const QString link = QLatin1String(urlC) + QLatin1String("quiet-paste.php");
......
......@@ -48,6 +48,7 @@ public:
virtual void fetch(const QString &id);
virtual void paste(const QString &text,
ContentType ct = Text,
int expiryDays = 1,
const QString &username = QString(),
const QString &comment = QString(),
const QString &description = QString());
......
......@@ -99,7 +99,7 @@ static inline QByteArray format(Protocol::ContentType ct)
}
void PasteBinDotComProtocol::paste(const QString &text,
ContentType ct,
ContentType ct, int expiryDays,
const QString &username,
const QString &comment,
const QString &description)
......@@ -111,14 +111,14 @@ void PasteBinDotComProtocol::paste(const QString &text,
// Format body
QByteArray pasteData = API_KEY;
pasteData += "api_option=paste&";
pasteData += "api_paste_expire_date=1M&";
pasteData += "api_paste_expire_date=";
pasteData += QByteArray::number(expiryDays);
pasteData += "D&";
pasteData += format(ct);
pasteData += "api_paste_name=";
pasteData += QUrl::toPercentEncoding(username);
pasteData += "&api_paste_code=";
pasteData += QUrl::toPercentEncoding(fixNewLines(text));
// fire request
m_pasteReply = httpPost(QLatin1String(PASTEBIN_BASE) + QLatin1String(PASTEBIN_API), pasteData);
connect(m_pasteReply, SIGNAL(finished()), this, SLOT(pasteFinished()));
......
......@@ -48,6 +48,7 @@ public:
virtual void fetch(const QString &id);
virtual void paste(const QString &text,
ContentType ct = Text,
int expiryDays = 1,
const QString &username = QString(),
const QString &comment = QString(),
const QString &description = QString());
......
......@@ -144,7 +144,7 @@ int PasteView::showDialog()
// Show up with checkable list of diff chunks.
int PasteView::show(const QString &user, const QString &description,
const QString &comment, const FileDataList &parts)
const QString &comment, int expiryDays, const FileDataList &parts)
{
setupDialog(user, description, comment);
m_ui.uiPatchList->clear();
......@@ -159,20 +159,32 @@ int PasteView::show(const QString &user, const QString &description,
}
m_ui.stackedWidget->setCurrentIndex(0);
m_ui.uiPatchView->setPlainText(content);
setExpiryDays(expiryDays);
return showDialog();
}
// Show up with editable plain text.
int PasteView::show(const QString &user, const QString &description,
const QString &comment, const QString &content)
const QString &comment, int expiryDays, const QString &content)
{
setupDialog(user, description, comment);
m_mode = PlainTextMode;
m_ui.stackedWidget->setCurrentIndex(1);
m_ui.plainTextEdit->setPlainText(content);
setExpiryDays(expiryDays);
return showDialog();
}
void PasteView::setExpiryDays(int d)
{
m_ui.expirySpinBox->setValue(d);
}
int PasteView::expiryDays() const
{
return m_ui.expirySpinBox->value();
}
void PasteView::accept()
{
const int index = m_ui.protocolBox->currentIndex();
......@@ -189,7 +201,7 @@ void PasteView::accept()
return;
const Protocol::ContentType ct = Protocol::contentType(m_mimeType);
protocol->paste(data, ct, user(), comment(), description());
protocol->paste(data, ct, expiryDays(), user(), comment(), description());
// Store settings and close
QSettings *settings = Core::ICore::settings();
settings->beginGroup(QLatin1String(groupC));
......
......@@ -56,10 +56,10 @@ public:
// Show up with checkable list of diff chunks.
int show(const QString &user, const QString &description, const QString &comment,
const FileDataList &parts);
int expiryDays, const FileDataList &parts);
// Show up with editable plain text.
int show(const QString &user, const QString &description, const QString &comment,
const QString &content);
int expiryDays, const QString &content);
void setProtocol(const QString &protocol);
......@@ -68,6 +68,8 @@ public:
QString comment() const;
QString content() const;
QString protocol() const;
void setExpiryDays(int d);
int expiryDays() const;
virtual void accept();
......
......@@ -26,7 +26,7 @@
<item row="0" column="1">
<widget class="QComboBox" name="protocolBox"/>
</item>
<item row="1" column="0">
<item row="2" column="0">
<widget class="QLabel" name="userLabel">
<property name="text">
<string>&amp;Username:</string>
......@@ -36,14 +36,14 @@
</property>
</widget>
</item>
<item row="1" column="1">
<item row="2" column="1">
<widget class="QLineEdit" name="uiUsername">
<property name="placeholderText">
<string>&lt;Username&gt;</string>
</property>
</widget>
</item>
<item row="2" column="0">
<item row="3" column="0">
<widget class="QLabel" name="descriptionLabel">
<property name="text">
<string>&amp;Description:</string>
......@@ -53,13 +53,36 @@
</property>
</widget>
</item>
<item row="2" column="1">
<item row="3" column="1">
<widget class="QLineEdit" name="uiDescription">
<property name="placeholderText">
<string>&lt;Description&gt;</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QSpinBox" name="expirySpinBox">
<property name="suffix">
<string>Days</string>
</property>
<property name="minimum">
<number>1</number>
</property>
<property name="maximum">
<number>365</number>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="expiryLabel">
<property name="text">
<string>&amp;Expires after:</string>
</property>
<property name="buddy">
<cstring>expirySpinBox</cstring>
</property>
</widget>
</item>
</layout>
</item>
<item>
......
......@@ -74,6 +74,7 @@ public:
virtual void list();
virtual void paste(const QString &text,
ContentType ct = Text,
int expiryDays = 1,
const QString &username = QString(),
const QString &comment = QString(),
const QString &description = QString()) = 0;
......
......@@ -36,20 +36,22 @@
static const char groupC[] = "CodePaster";
static const char userNameKeyC[] = "UserName";
static const char expiryDaysKeyC[] = "ExpiryDays";
static const char defaultProtocolKeyC[] = "DefaultProtocol";
static const char copyToClipboardKeyC[] = "CopyToClipboard";
static const char displayOutputKeyC[] = "DisplayOutput";
namespace CodePaster {
Settings::Settings() : copyToClipboard(true), displayOutput(true)
Settings::Settings() : expiryDays(1), copyToClipboard(true), displayOutput(true)
{
}
bool Settings::equals(const Settings &rhs) const
{
return copyToClipboard == rhs.copyToClipboard && displayOutput == rhs.displayOutput
&& username == rhs.username && protocol == rhs.protocol;
&& expiryDays == rhs.expiryDays && username == rhs.username
&& protocol == rhs.protocol;
}
void Settings::toSettings(QSettings *settings) const
......@@ -57,6 +59,7 @@ void Settings::toSettings(QSettings *settings) const
settings->beginGroup(QLatin1String(groupC));
settings->setValue(QLatin1String(userNameKeyC), username);
settings->setValue(QLatin1String(defaultProtocolKeyC), protocol);
settings->setValue(QLatin1String(expiryDaysKeyC), expiryDays);
settings->setValue(QLatin1String(copyToClipboardKeyC), copyToClipboard);
settings->setValue(QLatin1String(displayOutputKeyC), displayOutput);
settings->endGroup();
......@@ -66,6 +69,7 @@ void Settings::fromSettings(const QSettings *settings)
{
const QString rootKey = QLatin1String(groupC) + QLatin1Char('/');
const QString defaultUser = Utils::Environment::systemEnvironment().userName();
expiryDays = settings->value(rootKey + QLatin1String(expiryDaysKeyC), 1).toInt();
username = settings->value(rootKey + QLatin1String(userNameKeyC), defaultUser).toString();
protocol = settings->value(rootKey + QLatin1String(defaultProtocolKeyC), PasteBinDotComProtocol::protocolName()).toString();
copyToClipboard = settings->value(rootKey + QLatin1String(copyToClipboardKeyC), true).toBool();
......
......@@ -46,6 +46,7 @@ struct Settings {
QString username;
QString protocol;
int expiryDays;
bool copyToClipboard;
bool displayOutput;
};
......
......@@ -59,6 +59,7 @@ void SettingsWidget::setSettings(const Settings &settings)
m_ui.userEdit->setText(settings.username);
const int index = m_ui.defaultProtocol->findText(settings.protocol);
m_ui.defaultProtocol->setCurrentIndex(index == -1 ? 0 : index);
m_ui.expirySpinBox->setValue(settings.expiryDays);
m_ui.clipboardBox->setChecked(settings.copyToClipboard);
m_ui.displayBox->setChecked(settings.displayOutput);
}
......@@ -68,6 +69,7 @@ Settings SettingsWidget::settings()
Settings rc;
rc.username = m_ui.userEdit->text();
rc.protocol = m_ui.defaultProtocol->currentText();
rc.expiryDays = m_ui.expirySpinBox->value();
rc.copyToClipboard = m_ui.clipboardBox->isChecked();
rc.displayOutput = m_ui.displayBox->isChecked();
return rc;
......
......@@ -11,7 +11,14 @@
</rect>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="8" column="0" colspan="2">
<item row="4" column="0" colspan="2">
<widget class="QCheckBox" name="clipboardBox">
<property name="text">
<string>Copy-paste URL to clipboard</string>
</property>
</widget>
</item>
<item row="9" column="0" colspan="2">
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
......@@ -24,22 +31,35 @@
</property>
</spacer>
</item>
<item row="4" column="0" colspan="2">
<widget class="QCheckBox" name="displayBox">
<item row="1" column="1">
<widget class="QLineEdit" name="userEdit"/>
</item>
<item row="0" column="1">
<widget class="QComboBox" name="defaultProtocol"/>
</item>
<item row="0" column="0">
<widget class="QLabel" name="protocolLabel">
<property name="text">
<string>Display Output pane after sending a post</string>
<string>Default protocol:</string>
</property>
</widget>
</item>
<item row="3" column="0" colspan="2">
<widget class="QCheckBox" name="clipboardBox">
<item row="2" column="0">
<widget class="QLabel" name="expiryLabel">
<property name="text">
<string>Copy-paste URL to clipboard</string>
<string>&amp;Expires after:</string>
</property>
<property name="buddy">
<cstring>expirySpinBox</cstring>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QLineEdit" name="userEdit"/>
<item row="5" column="0" colspan="2">
<widget class="QCheckBox" name="displayBox">
<property name="text">
<string>Display Output pane after sending a post</string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="userNameLabel">
......@@ -48,13 +68,16 @@
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QComboBox" name="defaultProtocol"/>
</item>
<item row="0" column="0">
<widget class="QLabel" name="protocolLabel">
<property name="text">
<string>Default protocol:</string>
<item row="2" column="1">
<widget class="QSpinBox" name="expirySpinBox">
<property name="suffix">
<string>Days</string>
</property>
<property name="minimum">
<number>1</number>
</property>
<property name="maximum">
<number>365</number>
</property>
</widget>
</item>
......
......@@ -71,7 +71,7 @@ void UrlOpenProtocol::fetchFinished()
emit fetchDone(title, content, error);
}
void UrlOpenProtocol::paste(const QString &, ContentType, const QString &,
void UrlOpenProtocol::paste(const QString &, ContentType, int, const QString &,
const QString &, const QString &)
{
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment