Remove Files from Queue from Transfer Window

Problems compiling? Don't understand the source code? Don't know how to code your feature? Post here.

Moderator: Moderators

Locked
darwusch
Posts: 23
Joined: 2004-03-19 12:57

Remove Files from Queue from Transfer Window

Post by darwusch » 2004-06-30 03:28

"Remove Files from Queue from Transfer Window"

This has been mentioned before. See also this thread:
http://dcplusplus.sourceforge.net/forum ... e+transfer
(suggestion number 2 in the upper post)

And also in the requested features:
http://sourceforge.net/tracker/index.ph ... tid=427635

It seems a great option to me, that's why I decided to try and implement it in the source.
But this seems a bit hard for me, being a bad coder...

In the TransferView.h file, I started with using the "close connection" option to do this, only to test the working.

To me it seems that in the file QueueFrame.h, the onRemove option, using the removeSelected option are doing the trick in the QueueFrame.

So I tried to use those in the TransferView.h. For this I put and extra "#include "QueueFrame.h" in the TransferView.h and changed the behaviour from "close connection" to the one from "remove" from the queueframe.

But this doesn't do the trick. It compiles fine, but when I try it, nothing happens...

Can anybody help me code this feature ?
Maybe together we can do this !

Thanks !

Twink
Posts: 436
Joined: 2003-03-31 23:31
Location: New Zealand

Post by Twink » 2004-06-30 06:19

QueueManager::getInstance()->remove(target);

may be of use, however you dont actually have a target in the transferview, if you look in TransferView::OnDownloadStarting you'll notice

i->file = Util::getFileName(aDownload->getTarget());
i->path = Util::getFilePath(aDownload->getTarget());

you could try put i->file and i->path back together to get the target i guess.

you'll also have to append a remove item to transferMenu, most likely done in the onCreate funtion.

darwusch
Posts: 23
Joined: 2004-03-19 12:57

Post by darwusch » 2004-06-30 08:09

Thanks for your reply.

The extra menu item was no problem, just the actual task it performs.

I tried what you said, using the following code:

Code: Select all

	LRESULT onRemoveEntry(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/) {
		QueueManager::getInstance()->remove(TransferView::ItemInfo::path + TransferView::ItemInfo::file);
		return 0;
	}
So the target has been put together by adding the path and the filename.
It compiles fine, but when I use it, the dubugger holds at line 212 from the file malloc.c.
Meaning: It crashes.

What am I doing wrong here ?

Thanks for helping me.

GargoyleMT
DC++ Contributor
Posts: 3212
Joined: 2003-01-07 21:46
Location: .pa.us

Post by GargoyleMT » 2004-06-30 08:22

You have to get the selected items out of the listview, and operate on those. Look at the following example of an existing context menu:

Code: Select all

LRESULT TransferView::onForce(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/) {
	int i = -1;
	while( (i = ctrlTransfers.GetNextItem(i, LVNI_SELECTED)) != -1) {
		ctrlTransfers.SetItemText(i, COLUMN_STATUS, CSTRING(CONNECTING_FORCED));
		ctrlTransfers.getItemData(i)->user->connect();
	}
	return 0;
}

darwusch
Posts: 23
Joined: 2004-03-19 12:57

Post by darwusch » 2004-06-30 15:49

Thank you both guys, I got it to work !!

Using this code:

Code: Select all

	LRESULT onRemoveEntry(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/) { 
    int i = -1; 
	string file_target;
	string path_target;
	string total_target;
		while( (i = ctrlTransfers.GetNextItem(i, LVNI_SELECTED)) != -1) { 
			file_target = ctrlTransfers.getItemData(i)->getText(COLUMN_FILE);
			path_target = ctrlTransfers.getItemData(i)->getText(COLUMN_PATH);
			total_target = path_target + file_target;
			QueueManager::getInstance()->remove(total_target);
		} 
	return 0; 
	}
Thanks for helping me !

PseudonympH
Forum Moderator
Posts: 366
Joined: 2004-03-06 02:46

Post by PseudonympH » 2004-06-30 22:42

you should be l33t and use temporaries so you only have to have one line of code in the loop ;)

Code: Select all

QueueManager::getInstance()->remove( ctrlTransfers.getItemData(i)->getText(COLUMN_PATH) + ctrlTransfers.getItemData(i)->getText(COLUMN_FILE) );
and like magic, it is now both 6 fewer lines of code and, as an added benefit, much less readable!

Twink
Posts: 436
Joined: 2003-03-31 23:31
Location: New Zealand

Post by Twink » 2004-07-01 20:39

what really should be done is sticking with the convention used in dc++ and use

Code: Select all

LRESULT TransferView::onRemoveEntry(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/) {
   ctrlTransfers.forEachSelected(&ItemInfo::removeEntry);
	return 0;
}
then add

Code: Select all

void TransferView::ItemInfo::removeEntry() {
	if(type == TYPE_DOWNLOAD) {
		disconnect();
		QueueManager::getInstance()->remove(path + file );
	}
}
not sure if this would work though.

darwusch
Posts: 23
Joined: 2004-03-19 12:57

Post by darwusch » 2004-07-02 02:59

Looks better, that's for sure...
Just tested it: It also works fine.

Only it doesn't seem possible (with any of above mentioned code) to use this option if the status is "Connecting...".
I guess this is because at this moment the path and file is not known yet ?
Still it is possible to use the remove option from the queue itself, so I think it should be possible to use the new option also for "Connecting..." status.

Twink
Posts: 436
Joined: 2003-03-31 23:31
Location: New Zealand

Post by Twink » 2004-07-02 07:10

I'm not sure if dc++ decides which file to get until its actually connected, the other thing my code does is check if its a download first, ie it doesn't do anything if you right click an upload and remove it.

GargoyleMT
DC++ Contributor
Posts: 3212
Joined: 2003-01-07 21:46
Location: .pa.us

Post by GargoyleMT » 2004-07-02 07:44

Twink wrote:I'm not sure if dc++ decides which file to get until its actually connected
It doesn't, though the filename hint might lead one to believe otherwise.

JohnSmith
Posts: 3
Joined: 2004-07-24 15:26
Location: Belgrade, Serbia & Montenegro

Post by JohnSmith » 2004-07-24 15:37

Twink wrote:what really should be done is sticking with the convention used in dc++ and use

Code: Select all

LRESULT TransferView::onRemoveEntry(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/) {
   ctrlTransfers.forEachSelected(&ItemInfo::removeEntry);
	return 0;
}
then add

Code: Select all

void TransferView::ItemInfo::removeEntry() {
	if(type == TYPE_DOWNLOAD) {
		disconnect();
		QueueManager::getInstance()->remove(path + file );
	}
}
not sure if this would work though.
I was also interested in adding this menu item, but the one which would also work for "Connecting..." status. I thought at first to add some bool member to TransferView::ItemInfo, say removedFromMenu, and set it to true just before your call to disconnect() in the above code, and when disconnect() later (implicitly) calls TransferView::on(DownloadManagerListener::Failed), we will get file and path information of a transfer and we could check if it was removed from our menu and call QueueManager::remove() from there.

But then I came up with another solution:

Code: Select all

    if (type == TYPE_DOWNLOAD) {
        if (path.empty() || file.empty())
            QueueManager::getInstance()->removeRunningDownload(user);
        else {
            //disconnect();
            QueueManager::getInstance()->remove(path + file);
        }
    }
You will need to add the following function to the QueueManager class, either in public, or add TransferView::ItemInfo there as a friend:

Code: Select all

void QueueManager::removeRunningDownload(User::Ptr& aUser) throw() {
    string x;
    {
        Lock l(cs);
        QueueItem* q = userQueue.getRunning(aUser);
        ...
        // the rest is identical to QueueManager::remove(const string&)
}
I'm not sure that it is safe, though. It works on my machine! :) Maybe some of you DC++ gurus could verify that it's ok. Or the first approach is better?!

Is there a more elegant solution?

jsmith

Locked