2009-04-09 18:55:47 +00:00
|
|
|
/*
|
2014-01-19 01:09:44 +00:00
|
|
|
* This file Copyright (C) 2009-2014 Mnemosyne LLC
|
2009-04-09 18:55:47 +00:00
|
|
|
*
|
2014-01-19 01:09:44 +00:00
|
|
|
* It may be used under the GNU Public License v2 or v3 licenses,
|
|
|
|
* or any future license endorsed by Mnemosyne LLC.
|
2009-04-09 18:55:47 +00:00
|
|
|
*
|
2009-05-31 19:33:48 +00:00
|
|
|
* $Id$
|
2009-04-09 18:55:47 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <cassert>
|
|
|
|
#include <iostream>
|
|
|
|
|
2009-10-05 19:53:38 +00:00
|
|
|
#include <QCheckBox>
|
2009-04-09 18:55:47 +00:00
|
|
|
#include <QDialogButtonBox>
|
|
|
|
#include <QFileDialog>
|
2009-10-05 19:53:38 +00:00
|
|
|
#include <QFileIconProvider>
|
|
|
|
#include <QHBoxLayout>
|
2009-04-09 18:55:47 +00:00
|
|
|
#include <QLabel>
|
|
|
|
#include <QLineEdit>
|
|
|
|
#include <QList>
|
2013-07-27 21:58:14 +00:00
|
|
|
#include <QMimeData>
|
2009-10-05 19:53:38 +00:00
|
|
|
#include <QPlainTextEdit>
|
2009-04-09 18:55:47 +00:00
|
|
|
#include <QProgressBar>
|
2009-10-05 19:53:38 +00:00
|
|
|
#include <QPushButton>
|
|
|
|
#include <QRadioButton>
|
|
|
|
#include <QSize>
|
|
|
|
#include <QStyle>
|
|
|
|
#include <QTimer>
|
|
|
|
#include <QVBoxLayout>
|
2009-04-09 18:55:47 +00:00
|
|
|
|
|
|
|
#include <libtransmission/transmission.h>
|
|
|
|
#include <libtransmission/makemeta.h>
|
|
|
|
#include <libtransmission/utils.h>
|
|
|
|
|
2010-07-03 01:10:36 +00:00
|
|
|
#include "formatter.h"
|
2009-04-09 18:55:47 +00:00
|
|
|
#include "hig.h"
|
|
|
|
#include "make-dialog.h"
|
2009-10-05 19:53:38 +00:00
|
|
|
#include "session.h"
|
2013-09-08 19:59:47 +00:00
|
|
|
#include "utils.h"
|
2009-04-09 18:55:47 +00:00
|
|
|
|
|
|
|
/***
|
|
|
|
****
|
|
|
|
***/
|
|
|
|
|
|
|
|
void
|
2013-09-14 22:45:04 +00:00
|
|
|
MakeDialog :: onNewDialogDestroyed (QObject * o)
|
2009-04-09 18:55:47 +00:00
|
|
|
{
|
2013-09-14 22:45:04 +00:00
|
|
|
Q_UNUSED (o);
|
2009-04-09 18:55:47 +00:00
|
|
|
|
2013-09-14 22:45:04 +00:00
|
|
|
myTimer.stop ();
|
2009-04-09 18:55:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2013-09-14 22:45:04 +00:00
|
|
|
MakeDialog :: onNewButtonBoxClicked (QAbstractButton * button)
|
2009-04-09 18:55:47 +00:00
|
|
|
{
|
2013-09-14 22:45:04 +00:00
|
|
|
switch (myNewButtonBox->standardButton (button))
|
2009-10-05 19:53:38 +00:00
|
|
|
{
|
2013-09-14 22:45:04 +00:00
|
|
|
case QDialogButtonBox::Open:
|
|
|
|
mySession.addNewlyCreatedTorrent (myTarget, QFileInfo(QString::fromUtf8(myBuilder->top)).dir().path());
|
|
|
|
break;
|
2009-04-09 18:55:47 +00:00
|
|
|
|
2013-09-14 22:45:04 +00:00
|
|
|
case QDialogButtonBox::Abort:
|
|
|
|
myBuilder->abortFlag = true;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default: // QDialogButtonBox::Ok:
|
|
|
|
break;
|
2009-10-05 19:53:38 +00:00
|
|
|
}
|
2013-09-14 22:45:04 +00:00
|
|
|
|
|
|
|
myNewDialog->deleteLater ();
|
2009-04-09 18:55:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2013-09-14 22:45:04 +00:00
|
|
|
MakeDialog :: onProgress ()
|
2009-04-09 18:55:47 +00:00
|
|
|
{
|
2013-09-14 22:45:04 +00:00
|
|
|
// progress bar
|
|
|
|
const tr_metainfo_builder * b = myBuilder;
|
|
|
|
const double denom = b->pieceCount ? b->pieceCount : 1;
|
|
|
|
myNewProgress->setValue ((int) ((100.0 * b->pieceIndex) / denom));
|
|
|
|
|
|
|
|
// progress label
|
|
|
|
const QString top = QString::fromLocal8Bit (myBuilder->top);
|
|
|
|
const QString base (QFileInfo(top).completeBaseName());
|
|
|
|
QString str;
|
|
|
|
if (!b->isDone)
|
|
|
|
str = tr ("Creating \"%1\"").arg (base);
|
|
|
|
else if (b->result == TR_MAKEMETA_OK)
|
|
|
|
str = tr ("Created \"%1\"!").arg (base);
|
|
|
|
else if (b->result == TR_MAKEMETA_URL)
|
|
|
|
str = tr ("Error: invalid announce URL \"%1\"").arg (QString::fromLocal8Bit (b->errfile));
|
|
|
|
else if (b->result == TR_MAKEMETA_CANCELLED)
|
|
|
|
str = tr ("Cancelled");
|
|
|
|
else if (b->result == TR_MAKEMETA_IO_READ)
|
|
|
|
str = tr ("Error reading \"%1\": %2").arg (QString::fromLocal8Bit(b->errfile)).arg (QString::fromLocal8Bit(strerror(b->my_errno)));
|
|
|
|
else if (b->result == TR_MAKEMETA_IO_WRITE)
|
|
|
|
str = tr ("Error writing \"%1\": %2").arg (QString::fromLocal8Bit(b->errfile)).arg (QString::fromLocal8Bit(strerror(b->my_errno)));
|
|
|
|
myNewLabel->setText (str);
|
|
|
|
|
|
|
|
// buttons
|
|
|
|
(myNewButtonBox->button(QDialogButtonBox::Abort))->setEnabled (!b->isDone);
|
|
|
|
(myNewButtonBox->button(QDialogButtonBox::Ok))->setEnabled (b->isDone);
|
|
|
|
(myNewButtonBox->button(QDialogButtonBox::Open))->setEnabled (b->isDone && !b->result);
|
2009-04-09 18:55:47 +00:00
|
|
|
}
|
|
|
|
|
2009-10-05 19:53:38 +00:00
|
|
|
|
2009-04-09 18:55:47 +00:00
|
|
|
void
|
2013-09-14 22:45:04 +00:00
|
|
|
MakeDialog :: makeTorrent ()
|
2009-04-09 18:55:47 +00:00
|
|
|
{
|
2013-09-14 22:45:04 +00:00
|
|
|
if (!myBuilder)
|
|
|
|
return;
|
|
|
|
|
|
|
|
// get the tiers
|
|
|
|
int tier = 0;
|
|
|
|
QVector<tr_tracker_info> trackers;
|
|
|
|
foreach (QString line, myTrackerEdit->toPlainText().split("\n"))
|
|
|
|
{
|
|
|
|
line = line.trimmed ();
|
|
|
|
if (line.isEmpty ())
|
|
|
|
{
|
|
|
|
++tier;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
tr_tracker_info tmp;
|
|
|
|
tmp.announce = tr_strdup (line.toUtf8().constData ());
|
|
|
|
tmp.tier = tier;
|
|
|
|
trackers.append (tmp);
|
2009-04-09 18:55:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-09-14 22:45:04 +00:00
|
|
|
// pop up the dialog
|
|
|
|
QDialog * dialog = new QDialog (this);
|
|
|
|
dialog->setWindowTitle (tr ("New Torrent"));
|
|
|
|
myNewDialog = dialog;
|
|
|
|
QVBoxLayout * top = new QVBoxLayout (dialog);
|
|
|
|
top->addWidget( (myNewLabel = new QLabel));
|
|
|
|
top->addWidget( (myNewProgress = new QProgressBar));
|
|
|
|
QDialogButtonBox * buttons = new QDialogButtonBox (QDialogButtonBox::Ok
|
|
|
|
| QDialogButtonBox::Open
|
|
|
|
| QDialogButtonBox::Abort);
|
|
|
|
myNewButtonBox = buttons;
|
|
|
|
connect (buttons, SIGNAL(clicked(QAbstractButton*)),
|
|
|
|
this, SLOT(onNewButtonBoxClicked(QAbstractButton*)));
|
|
|
|
top->addWidget (buttons);
|
|
|
|
onProgress ();
|
|
|
|
dialog->show ();
|
|
|
|
connect (dialog, SIGNAL(destroyed(QObject*)),
|
|
|
|
this, SLOT(onNewDialogDestroyed(QObject*)));
|
|
|
|
myTimer.start (100);
|
|
|
|
|
|
|
|
// the file to create
|
|
|
|
const QString path = QString::fromUtf8 (myBuilder->top);
|
|
|
|
const QString torrentName = QFileInfo(path).completeBaseName() + ".torrent";
|
|
|
|
myTarget = QDir (myDestination).filePath (torrentName);
|
|
|
|
|
|
|
|
// comment
|
|
|
|
QString comment;
|
|
|
|
if (myCommentCheck->isChecked())
|
|
|
|
comment = myCommentEdit->text();
|
|
|
|
|
|
|
|
// start making the torrent
|
|
|
|
tr_makeMetaInfo (myBuilder,
|
|
|
|
myTarget.toUtf8().constData(),
|
|
|
|
(trackers.isEmpty() ? NULL : trackers.data()),
|
|
|
|
trackers.size(),
|
|
|
|
(comment.isEmpty() ? NULL : comment.toUtf8().constData()),
|
|
|
|
myPrivateCheck->isChecked());
|
2009-04-09 18:55:47 +00:00
|
|
|
}
|
|
|
|
|
2009-10-05 19:53:38 +00:00
|
|
|
/***
|
|
|
|
****
|
|
|
|
***/
|
|
|
|
|
2009-04-09 18:55:47 +00:00
|
|
|
void
|
2013-09-14 22:45:04 +00:00
|
|
|
MakeDialog :: onFileClicked ()
|
2009-04-09 18:55:47 +00:00
|
|
|
{
|
2013-09-14 22:45:04 +00:00
|
|
|
QFileDialog * d = new QFileDialog (this, tr ("Select File"));
|
|
|
|
d->setFileMode (QFileDialog::ExistingFile);
|
|
|
|
d->setAttribute (Qt::WA_DeleteOnClose);
|
|
|
|
connect (d, SIGNAL(filesSelected(const QStringList&)),
|
|
|
|
this, SLOT(onFileSelected(const QStringList&)));
|
|
|
|
d->show ();
|
2009-10-05 19:53:38 +00:00
|
|
|
}
|
|
|
|
void
|
2013-09-14 22:45:04 +00:00
|
|
|
MakeDialog :: onFileSelected (const QStringList& list)
|
2009-10-05 19:53:38 +00:00
|
|
|
{
|
2013-09-14 22:45:04 +00:00
|
|
|
if (!list.empty ())
|
|
|
|
onFileSelected (list.front ());
|
2010-08-02 20:55:11 +00:00
|
|
|
}
|
|
|
|
void
|
2013-09-14 22:45:04 +00:00
|
|
|
MakeDialog :: onFileSelected (const QString& filename)
|
2010-08-02 20:55:11 +00:00
|
|
|
{
|
2013-09-14 22:45:04 +00:00
|
|
|
myFile = Utils::removeTrailingDirSeparator (filename);
|
|
|
|
myFileButton->setText (QFileInfo(myFile).fileName());
|
|
|
|
onSourceChanged ();
|
2009-10-05 19:53:38 +00:00
|
|
|
}
|
2009-04-09 18:55:47 +00:00
|
|
|
|
2009-10-05 19:53:38 +00:00
|
|
|
void
|
2013-09-14 22:45:04 +00:00
|
|
|
MakeDialog :: onFolderClicked ()
|
2009-10-05 19:53:38 +00:00
|
|
|
{
|
2013-09-14 22:45:04 +00:00
|
|
|
QFileDialog * d = new QFileDialog (this, tr ("Select Folder"));
|
|
|
|
d->setFileMode (QFileDialog::Directory);
|
|
|
|
d->setOption (QFileDialog::ShowDirsOnly);
|
|
|
|
d->setAttribute (Qt::WA_DeleteOnClose);
|
|
|
|
connect (d, SIGNAL(filesSelected(const QStringList&)),
|
|
|
|
this, SLOT(onFolderSelected(const QStringList&)));
|
|
|
|
d->show ();
|
2009-10-05 19:53:38 +00:00
|
|
|
}
|
2013-09-14 22:45:04 +00:00
|
|
|
|
2009-10-05 19:53:38 +00:00
|
|
|
void
|
2013-09-14 22:45:04 +00:00
|
|
|
MakeDialog :: onFolderSelected (const QStringList& list)
|
2009-10-05 19:53:38 +00:00
|
|
|
{
|
2013-09-14 22:45:04 +00:00
|
|
|
if (!list.empty ())
|
|
|
|
onFolderSelected (list.front ());
|
2010-08-02 20:55:11 +00:00
|
|
|
}
|
2013-09-14 22:45:04 +00:00
|
|
|
|
2010-08-02 20:55:11 +00:00
|
|
|
void
|
2013-09-14 22:45:04 +00:00
|
|
|
MakeDialog :: onFolderSelected (const QString& filename)
|
2010-08-02 20:55:11 +00:00
|
|
|
{
|
2013-09-14 22:45:04 +00:00
|
|
|
myFolder = Utils::removeTrailingDirSeparator (filename);
|
|
|
|
myFolderButton->setText (QFileInfo(myFolder).fileName());
|
|
|
|
onSourceChanged ();
|
2009-10-05 19:53:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2013-09-14 22:45:04 +00:00
|
|
|
MakeDialog :: onDestinationClicked ()
|
2009-10-05 19:53:38 +00:00
|
|
|
{
|
2013-09-14 22:45:04 +00:00
|
|
|
QFileDialog * d = new QFileDialog (this, tr ("Select Folder"));
|
|
|
|
d->setFileMode (QFileDialog::Directory);
|
|
|
|
d->setOption (QFileDialog::ShowDirsOnly);
|
|
|
|
d->setAttribute (Qt::WA_DeleteOnClose);
|
|
|
|
connect (d, SIGNAL(filesSelected(const QStringList&)),
|
|
|
|
this, SLOT(onDestinationSelected(const QStringList&)));
|
|
|
|
d->show ();
|
2009-10-05 19:53:38 +00:00
|
|
|
}
|
|
|
|
void
|
2013-09-14 22:45:04 +00:00
|
|
|
MakeDialog :: onDestinationSelected (const QStringList& list)
|
2009-10-05 19:53:38 +00:00
|
|
|
{
|
2013-09-14 22:45:04 +00:00
|
|
|
if (!list.empty ())
|
|
|
|
onDestinationSelected (list.front());
|
2010-08-02 20:55:11 +00:00
|
|
|
}
|
|
|
|
void
|
2013-09-14 22:45:04 +00:00
|
|
|
MakeDialog :: onDestinationSelected (const QString& filename)
|
2010-08-02 20:55:11 +00:00
|
|
|
{
|
2013-09-14 22:45:04 +00:00
|
|
|
myDestination = Utils::removeTrailingDirSeparator (filename);
|
|
|
|
myDestinationButton->setText (QFileInfo(myDestination).fileName());
|
2009-10-05 19:53:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2013-09-14 22:45:04 +00:00
|
|
|
MakeDialog :: enableBuddyWhenChecked (QRadioButton * box, QWidget * buddy)
|
2009-10-05 19:53:38 +00:00
|
|
|
{
|
2013-09-14 22:45:04 +00:00
|
|
|
connect (box, SIGNAL(toggled(bool)), buddy, SLOT(setEnabled(bool)));
|
|
|
|
buddy->setEnabled (box->isChecked ());
|
2009-10-05 19:53:38 +00:00
|
|
|
}
|
|
|
|
void
|
2013-09-14 22:45:04 +00:00
|
|
|
MakeDialog :: enableBuddyWhenChecked (QCheckBox * box, QWidget * buddy)
|
2009-10-05 19:53:38 +00:00
|
|
|
{
|
2013-09-14 22:45:04 +00:00
|
|
|
connect (box, SIGNAL(toggled(bool)), buddy, SLOT(setEnabled(bool)));
|
|
|
|
buddy->setEnabled (box->isChecked ());
|
2009-10-05 19:53:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
QString
|
2013-09-14 22:45:04 +00:00
|
|
|
MakeDialog :: getSource () const
|
2009-10-05 19:53:38 +00:00
|
|
|
{
|
2013-09-14 22:45:04 +00:00
|
|
|
return myFileRadio->isChecked () ? myFile : myFolder;
|
2009-10-05 19:53:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2013-09-14 22:45:04 +00:00
|
|
|
MakeDialog :: onButtonBoxClicked (QAbstractButton * button)
|
2009-10-05 19:53:38 +00:00
|
|
|
{
|
2013-09-14 22:45:04 +00:00
|
|
|
switch (myButtonBox->standardButton (button))
|
2009-10-05 19:53:38 +00:00
|
|
|
{
|
2013-09-14 22:45:04 +00:00
|
|
|
case QDialogButtonBox::Ok:
|
|
|
|
makeTorrent ();
|
|
|
|
break;
|
2009-04-09 18:55:47 +00:00
|
|
|
|
2013-09-14 22:45:04 +00:00
|
|
|
default: // QDialogButtonBox::Close:
|
|
|
|
deleteLater ();
|
|
|
|
break;
|
2009-10-05 19:53:38 +00:00
|
|
|
}
|
2009-04-09 18:55:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/***
|
|
|
|
****
|
|
|
|
***/
|
|
|
|
|
|
|
|
void
|
2013-09-14 22:45:04 +00:00
|
|
|
MakeDialog :: onSourceChanged ()
|
2009-04-09 18:55:47 +00:00
|
|
|
{
|
2013-09-14 22:45:04 +00:00
|
|
|
if (myBuilder)
|
2009-10-05 19:53:38 +00:00
|
|
|
{
|
2013-09-14 22:45:04 +00:00
|
|
|
tr_metaInfoBuilderFree (myBuilder);
|
|
|
|
myBuilder = 0;
|
2009-04-09 18:55:47 +00:00
|
|
|
}
|
|
|
|
|
2013-09-14 22:45:04 +00:00
|
|
|
const QString filename = getSource ();
|
|
|
|
if (!filename.isEmpty ())
|
|
|
|
myBuilder = tr_metaInfoBuilderCreate (filename.toUtf8().constData());
|
|
|
|
|
|
|
|
QString text;
|
|
|
|
if (!myBuilder)
|
|
|
|
{
|
|
|
|
text = tr ("<i>No source selected<i>");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
QString files = tr ("%Ln File(s)", 0, myBuilder->fileCount);
|
|
|
|
QString pieces = tr ("%Ln Piece(s)", 0, myBuilder->pieceCount);
|
|
|
|
text = tr ("%1 in %2; %3 @ %4")
|
|
|
|
.arg (Formatter::sizeToString (myBuilder->totalSize))
|
|
|
|
.arg (files)
|
|
|
|
.arg (pieces)
|
|
|
|
.arg (Formatter::sizeToString (myBuilder->pieceSize));
|
2009-04-09 18:55:47 +00:00
|
|
|
}
|
|
|
|
|
2013-09-14 22:45:04 +00:00
|
|
|
mySourceLabel->setText (text);
|
2009-04-09 18:55:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-10-05 19:53:38 +00:00
|
|
|
// bah, there doesn't seem to be any cleaner way to override
|
|
|
|
// QPlainTextEdit's default desire to be 12 lines tall
|
2013-09-14 22:45:04 +00:00
|
|
|
class ShortPlainTextEdit: public QPlainTextEdit
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
virtual ~ShortPlainTextEdit () {}
|
|
|
|
ShortPlainTextEdit (QWidget * parent = 0): QPlainTextEdit(parent) {}
|
|
|
|
virtual QSize sizeHint () const { return QSize (256, 50); }
|
2009-10-05 19:53:38 +00:00
|
|
|
};
|
|
|
|
|
2013-09-14 22:45:04 +00:00
|
|
|
MakeDialog :: MakeDialog (Session & session, QWidget * parent):
|
|
|
|
QDialog (parent, Qt::Dialog),
|
|
|
|
mySession (session),
|
|
|
|
myBuilder (0)
|
2009-04-09 18:55:47 +00:00
|
|
|
{
|
2013-09-14 22:45:04 +00:00
|
|
|
setAcceptDrops (true);
|
|
|
|
|
|
|
|
connect (&myTimer, SIGNAL(timeout()), this, SLOT(onProgress()));
|
|
|
|
|
|
|
|
setWindowTitle (tr ("New Torrent"));
|
|
|
|
QVBoxLayout * top = new QVBoxLayout (this);
|
|
|
|
top->setSpacing (HIG :: PAD);
|
|
|
|
|
|
|
|
HIG * hig = new HIG;
|
|
|
|
hig->setContentsMargins (0, 0, 0, 0);
|
|
|
|
hig->addSectionTitle (tr ("Files"));
|
|
|
|
|
|
|
|
QFileIconProvider iconProvider;
|
|
|
|
const int iconSize (style()->pixelMetric (QStyle::PM_SmallIconSize));
|
|
|
|
const QIcon folderIcon = iconProvider.icon (QFileIconProvider::Folder);
|
|
|
|
const QPixmap folderPixmap = folderIcon.pixmap (iconSize);
|
|
|
|
QPushButton * b = new QPushButton;
|
|
|
|
b->setIcon (folderPixmap);
|
|
|
|
b->setStyleSheet (QString::fromUtf8 ("text-align: left; padding-left: 5; padding-right: 5"));
|
|
|
|
myDestination = QDir::homePath();
|
|
|
|
b->setText (myDestination);
|
|
|
|
connect (b, SIGNAL(clicked(bool)),
|
|
|
|
this, SLOT(onDestinationClicked(void)));
|
|
|
|
myDestinationButton = b;
|
|
|
|
hig->addRow (tr ("Sa&ve to:"), b);
|
|
|
|
|
|
|
|
myFolderRadio = new QRadioButton (tr ("Source F&older:"));
|
|
|
|
connect (myFolderRadio, SIGNAL(toggled(bool)),
|
|
|
|
this, SLOT(onSourceChanged()));
|
|
|
|
myFolderButton = new QPushButton;
|
|
|
|
myFolderButton->setIcon (folderPixmap);
|
|
|
|
myFolderButton->setText (tr ("(None)"));
|
|
|
|
myFolderButton->setStyleSheet (QString::fromUtf8 ("text-align: left; padding-left: 5; padding-right: 5"));
|
|
|
|
connect (myFolderButton, SIGNAL(clicked(bool)),
|
|
|
|
this, SLOT(onFolderClicked(void)));
|
|
|
|
hig->addRow (myFolderRadio, myFolderButton);
|
|
|
|
enableBuddyWhenChecked (myFolderRadio, myFolderButton);
|
|
|
|
|
|
|
|
const QIcon fileIcon = iconProvider.icon (QFileIconProvider::File);
|
|
|
|
const QPixmap filePixmap = fileIcon.pixmap (iconSize);
|
|
|
|
myFileRadio = new QRadioButton (tr ("Source &File:"));
|
|
|
|
myFileRadio->setChecked (true);
|
|
|
|
connect (myFileRadio, SIGNAL(toggled(bool)),
|
|
|
|
this, SLOT(onSourceChanged()));
|
|
|
|
myFileButton = new QPushButton;
|
|
|
|
myFileButton->setText (tr ("(None)"));
|
|
|
|
myFileButton->setIcon (filePixmap);
|
|
|
|
myFileButton->setStyleSheet (QString::fromUtf8 ("text-align: left; padding-left: 5; padding-right: 5"));
|
|
|
|
connect (myFileButton, SIGNAL(clicked(bool)),
|
|
|
|
this, SLOT(onFileClicked(void)));
|
|
|
|
hig->addRow (myFileRadio, myFileButton);
|
|
|
|
enableBuddyWhenChecked (myFileRadio, myFileButton);
|
|
|
|
|
|
|
|
mySourceLabel = new QLabel (this);
|
|
|
|
hig->addRow (tr (""), mySourceLabel);
|
|
|
|
|
|
|
|
hig->addSectionDivider ();
|
|
|
|
hig->addSectionTitle (tr ("Properties"));
|
|
|
|
|
|
|
|
hig->addWideControl (myTrackerEdit = new ShortPlainTextEdit);
|
|
|
|
const int height = fontMetrics().size (0, QString::fromUtf8("\n\n\n\n")).height ();
|
|
|
|
myTrackerEdit->setMinimumHeight (height);
|
|
|
|
hig->addTallRow (tr ("&Trackers:"), myTrackerEdit);
|
|
|
|
QLabel * l = new QLabel (tr ("To add a backup URL, add it on the line after the primary URL.\nTo add another primary URL, add it after a blank line."));
|
|
|
|
l->setAlignment (Qt::AlignLeft);
|
|
|
|
hig->addRow (tr (""), l);
|
|
|
|
myTrackerEdit->resize (500, height);
|
|
|
|
|
|
|
|
myCommentCheck = new QCheckBox (tr ("Co&mment"));
|
|
|
|
myCommentEdit = new QLineEdit ();
|
|
|
|
hig->addRow (myCommentCheck, myCommentEdit);
|
|
|
|
enableBuddyWhenChecked (myCommentCheck, myCommentEdit);
|
|
|
|
|
|
|
|
myPrivateCheck = hig->addWideCheckBox (tr ("&Private torrent"), false);
|
|
|
|
|
|
|
|
hig->finish ();
|
|
|
|
top->addWidget (hig, 1);
|
|
|
|
|
|
|
|
myButtonBox = new QDialogButtonBox (QDialogButtonBox::Ok
|
|
|
|
| QDialogButtonBox::Close);
|
|
|
|
connect (myButtonBox, SIGNAL(clicked(QAbstractButton*)),
|
|
|
|
this, SLOT(onButtonBoxClicked(QAbstractButton*)));
|
|
|
|
|
|
|
|
top->addWidget (myButtonBox);
|
|
|
|
onSourceChanged ();
|
2009-04-09 18:55:47 +00:00
|
|
|
}
|
|
|
|
|
2013-09-14 22:45:04 +00:00
|
|
|
MakeDialog :: ~MakeDialog ()
|
2009-04-09 18:55:47 +00:00
|
|
|
{
|
2013-09-14 22:45:04 +00:00
|
|
|
if (myBuilder)
|
|
|
|
tr_metaInfoBuilderFree (myBuilder);
|
2009-04-09 18:55:47 +00:00
|
|
|
}
|
2010-08-02 20:55:11 +00:00
|
|
|
|
|
|
|
/***
|
|
|
|
****
|
|
|
|
***/
|
|
|
|
|
|
|
|
void
|
2013-09-14 22:45:04 +00:00
|
|
|
MakeDialog :: dragEnterEvent (QDragEnterEvent * event)
|
2010-08-02 20:55:11 +00:00
|
|
|
{
|
2013-09-14 22:45:04 +00:00
|
|
|
const QMimeData * mime = event->mimeData ();
|
2010-08-02 20:55:11 +00:00
|
|
|
|
2013-09-14 22:45:04 +00:00
|
|
|
if (mime->urls().size() && QFile(mime->urls().front().path()).exists ())
|
|
|
|
event->acceptProposedAction();
|
2010-08-02 20:55:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2013-09-14 22:45:04 +00:00
|
|
|
MakeDialog :: dropEvent (QDropEvent * event)
|
2010-08-02 20:55:11 +00:00
|
|
|
{
|
2013-09-14 22:45:04 +00:00
|
|
|
const QString filename = event->mimeData()->urls().front().path();
|
|
|
|
const QFileInfo fileInfo (filename);
|
2010-08-02 20:55:11 +00:00
|
|
|
|
2013-09-14 22:45:04 +00:00
|
|
|
if (fileInfo.exists ())
|
2010-08-02 20:55:11 +00:00
|
|
|
{
|
2013-09-14 22:45:04 +00:00
|
|
|
if (fileInfo.isDir ())
|
2010-08-02 20:55:11 +00:00
|
|
|
{
|
2013-09-14 22:45:04 +00:00
|
|
|
myFolderRadio->setChecked (true);
|
|
|
|
onFolderSelected (filename );
|
2010-08-02 20:55:11 +00:00
|
|
|
}
|
2013-09-14 22:45:04 +00:00
|
|
|
else // it's a file
|
2010-08-02 20:55:11 +00:00
|
|
|
{
|
2013-09-14 22:45:04 +00:00
|
|
|
myFileRadio->setChecked (true);
|
|
|
|
onFileSelected (filename);
|
2010-08-02 20:55:11 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|