Enabled drag and drop in ShareManager to add folders to the share.

Fixed german language.

git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@4172 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
thunder2 2011-04-26 23:38:29 +00:00
parent 993e0d225c
commit f29b41f303
4 changed files with 99 additions and 24 deletions

View file

@ -26,6 +26,7 @@
#include <QPoint>
#include <QHeaderView>
#include <QMessageBox>
#include <QUrl>
#include <retroshare/rsfiles.h>
@ -76,6 +77,7 @@ ShareManager::ShareManager(QWidget *parent, Qt::WFlags flags)
ui.shareddirList->setRangeSelected(QTableWidgetSelectionRange(0, 0, 0, COLUMN_COUNT), true);
setAcceptDrops(true);
setAttribute(Qt::WA_DeleteOnClose, true);
}
@ -306,3 +308,57 @@ void ShareManager::shareddirListCurrentCellChanged(int currentRow, int currentCo
ui.removeButton->setEnabled(false);
}
}
void ShareManager::dragEnterEvent(QDragEnterEvent *event)
{
if (event->mimeData()->hasUrls()) {
event->acceptProposedAction();
}
}
void ShareManager::dropEvent(QDropEvent *event)
{
if (!(Qt::CopyAction & event->possibleActions())) {
/* can't do it */
return;
}
QStringList formats = event->mimeData()->formats();
QStringList::iterator it;
bool errorShown = false;
if (event->mimeData()->hasUrls()) {
QList<QUrl> urls = event->mimeData()->urls();
QList<QUrl>::iterator it;
for (it = urls.begin(); it != urls.end(); it++) {
QString localpath = it->toLocalFile();
if (localpath.isEmpty() == false) {
QDir dir(localpath);
if (dir.exists()) {
SharedDirInfo sdi;
sdi.filename = localpath.toUtf8().constData();
sdi.virtualname.clear();
sdi.shareflags = 0;
/* add new share */
rsFiles->addSharedDirectory(sdi);
} else if (QFile::exists(localpath)) {
if (errorShown == false) {
QMessageBox mb(tr("Drop file error."), tr("File can't be dropped, only directories are accepted."), QMessageBox::Information, QMessageBox::Ok, 0, 0, this);
mb.exec();
errorShown = true;
}
} else {
QMessageBox mb(tr("Drop file error."), tr("Directory not found or directory name not accepted."), QMessageBox::Information, QMessageBox::Ok, 0, 0, this);
mb.exec();
}
}
}
}
event->setDropAction(Qt::CopyAction);
event->accept();
}