Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 9 additions & 7 deletions src/DownloadListCtrl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -583,7 +583,7 @@ void CDownloadListCtrl::OnPreviewFile(wxCommandEvent &WXUNUSED(event))
ItemList files = ::GetSelectedItems(this);

if (files.size() == 1) {
PreviewFile(files.front()->GetFile());
PreviewFile(files.front()->GetFile(), this);
}
}

Expand All @@ -592,7 +592,7 @@ void CDownloadListCtrl::OnItemActivated(wxListEvent &evt)
CPartFile *file = reinterpret_cast<FileCtrlItem_Struct *>(GetItemData(evt.GetIndex()))->GetFile();

if ((!file->IsPartFile() || file->IsCompleted()) && file->PreviewAvailable()) {
PreviewFile(file);
PreviewFile(file, this);
}
}

Expand Down Expand Up @@ -1379,7 +1379,7 @@ void CDownloadListCtrl::DrawFileStatusBar(
#define QUOTE "\'"
#endif

void CDownloadListCtrl::PreviewFile(CPartFile *file)
void CDownloadListCtrl::PreviewFile(CKnownFile *file, wxWindow *parent)
{
wxString command;
if (thePrefs::GetVideoPlayer().IsEmpty()) {
Expand Down Expand Up @@ -1410,7 +1410,7 @@ void CDownloadListCtrl::PreviewFile(CPartFile *file)
defaultPreview,
_("File preview"),
wxOK,
this);
parent);
} else {
command = thePrefs::GetVideoPlayer();
}
Expand All @@ -1421,13 +1421,15 @@ void CDownloadListCtrl::PreviewFile(CPartFile *file)
// Check if we are (pre)viewing a completed file or not
if (!file->IsCompleted()) {
// Remove the .met and see if out video player specifiation uses the magic string
partName = file->GetPartMetFileName().RemoveExt().GetRaw();
partFile = thePrefs::GetTempDir().JoinPaths(file->GetPartMetFileName().RemoveExt()).GetRaw();
CPartFile *partfile = static_cast<CPartFile *>(file);
partName = partfile->GetPartMetFileName().RemoveExt().GetRaw();
partFile =
thePrefs::GetTempDir().JoinPaths(partfile->GetPartMetFileName().RemoveExt()).GetRaw();
} else {
// This is a complete file
// FIXME: This is probably not going to work if the filenames are mangled ...
partName = file->GetFileName().GetRaw();
partFile = file->GetFullName().GetRaw();
partFile = file->GetFilePath().JoinPaths(file->GetFileName()).GetRaw();
}

// Compatibility with old behaviour
Expand Down
19 changes: 12 additions & 7 deletions src/DownloadListCtrl.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
#include "Constants.h" // Needed for DownloadItemType
#include "MuleListCtrl.h" // Needed for CMuleListCtrl

class CKnownFile;
class CPartFile;
class wxBitmap;
class wxRect;
Expand Down Expand Up @@ -130,6 +131,17 @@ class CDownloadListCtrl : public CMuleListCtrl
*/
void DoItemSelectionChanged();

/**
* Executes the user-selected preview command on the specified file.
*
* Works for incomplete downloads (previewing the partfile in the
* temp dir) as well as for completed/shared files.
*
* @param file The file to be previewed.
* @param parent Window used as parent for any message boxes.
*/
static void PreviewFile(CKnownFile *file, wxWindow *parent);

protected:
/// Return old column order.
wxString GetOldColumnOrder() const;
Expand Down Expand Up @@ -184,13 +196,6 @@ class CDownloadListCtrl : public CMuleListCtrl
void OnKeyPressed(wxKeyEvent &event);
void OnItemSelectionChanged(wxListEvent &event);

/**
* Executes the user-selected preview command on the specified file.
*
* @file The file to be previewed.
*/
void PreviewFile(CPartFile *file);

/**
* Show file detail dialog for item at index
*/
Expand Down
50 changes: 35 additions & 15 deletions src/SharedFilesCtrl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,21 +27,22 @@

#include <common/MenuIDs.h>

#include "muuli_wdr.h" // Needed for ID_SHFILELIST
#include "SharedFilesWnd.h" // Needed for CSharedFilesWnd
#include "amuleDlg.h" // Needed for CamuleDlg
#include "CommentDialog.h" // Needed for CCommentDialog
#include "PartFile.h" // Needed for CPartFile
#include "SharedFileList.h" // Needed for CKnownFileMap
#include "amule.h" // Needed for theApp
#include "ServerConnect.h" // Needed for CServerConnect
#include "Preferences.h" // Needed for thePrefs
#include "BarShader.h" // Needed for CBarShader
#include "DataToText.h" // Needed for PriorityToStr
#include "GuiEvents.h" // Needed for CoreNotify_*
#include "MuleCollection.h" // Needed for CMuleCollection
#include "DownloadQueue.h" // Needed for CDownloadQueue
#include "TransferWnd.h" // Needed for CTransferWnd
#include "muuli_wdr.h" // Needed for ID_SHFILELIST
#include "SharedFilesWnd.h" // Needed for CSharedFilesWnd
#include "amuleDlg.h" // Needed for CamuleDlg
#include "CommentDialog.h" // Needed for CCommentDialog
#include "PartFile.h" // Needed for CPartFile
#include "SharedFileList.h" // Needed for CKnownFileMap
#include "amule.h" // Needed for theApp
#include "ServerConnect.h" // Needed for CServerConnect
#include "Preferences.h" // Needed for thePrefs
#include "BarShader.h" // Needed for CBarShader
#include "DataToText.h" // Needed for PriorityToStr
#include "GuiEvents.h" // Needed for CoreNotify_*
#include "MuleCollection.h" // Needed for CMuleCollection
#include "DownloadQueue.h" // Needed for CDownloadQueue
#include "TransferWnd.h" // Needed for CTransferWnd
#include "DownloadListCtrl.h" // Needed for CDownloadListCtrl::PreviewFile

wxBEGIN_EVENT_TABLE(CSharedFilesCtrl, CMuleListCtrl)
EVT_LIST_ITEM_RIGHT_CLICK(-1, CSharedFilesCtrl::OnRightClick)
Expand All @@ -66,6 +67,7 @@ wxBEGIN_EVENT_TABLE(CSharedFilesCtrl, CMuleListCtrl)
EVT_MENU(MP_GETAICHED2KLINKSRC, CSharedFilesCtrl::OnCreateURI)
EVT_MENU(MP_RENAME, CSharedFilesCtrl::OnRename)
EVT_MENU(MP_WS, CSharedFilesCtrl::OnGetFeedback)
EVT_MENU(MP_VIEW, CSharedFilesCtrl::OnPlayFile)

EVT_CHAR(CSharedFilesCtrl::OnKeyPressed)
wxEND_EVENT_TABLE()
Expand Down Expand Up @@ -127,6 +129,10 @@ void CSharedFilesCtrl::OnRightClick(wxListEvent &event)

if ((m_menu == NULL) && (item_hit != -1)) {
m_menu = new wxMenu(_("Shared Files"));

m_menu->Append(MP_VIEW, _("&Play"));
m_menu->AppendSeparator();

wxMenu *prioMenu = new wxMenu();
prioMenu->AppendCheckItem(MP_PRIOVERYLOW, _("Very low"));
prioMenu->AppendCheckItem(MP_PRIOLOW, _("Low"));
Expand Down Expand Up @@ -166,6 +172,11 @@ void CSharedFilesCtrl::OnRightClick(wxListEvent &event)
m_menu->Append(MP_GETAICHED2KLINKSRC, _("Copy eD2k link to clipboard (&AICH info + Source)"));
m_menu->Append(MP_WS, _("Copy feedback to clipboard"));

// Incomplete files shared while downloading can only be played
// if enough of the beginning has been downloaded.
m_menu->Enable(
MP_VIEW, file->IsCompleted() || static_cast<CPartFile *>(file)->PreviewAvailable());

m_menu->Enable(MP_GETAICHED2KLINK, file->HasProperAICHHashSet());
m_menu->Enable(MP_GETAICHED2KLINKSRC, file->HasProperAICHHashSet());
m_menu->Enable(MP_GETHOSTNAMESOURCEED2KLINK, !thePrefs::GetYourHostname().IsEmpty());
Expand Down Expand Up @@ -764,6 +775,15 @@ void CSharedFilesCtrl::OnKeyPressed(wxKeyEvent &event)
event.Skip();
}

void CSharedFilesCtrl::OnPlayFile(wxCommandEvent &WXUNUSED(event))
{
if (GetSelectedItemCount() == 1) {
long index = GetNextItem(-1, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED);

CDownloadListCtrl::PreviewFile(reinterpret_cast<CKnownFile *>(GetItemData(index)), this);
}
}

void CSharedFilesCtrl::OnAddCollection(wxCommandEvent &WXUNUSED(evt))
{
int item = GetNextItem(-1, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED);
Expand Down
5 changes: 5 additions & 0 deletions src/SharedFilesCtrl.h
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,11 @@ class CSharedFilesCtrl : public CMuleListCtrl
*/
void OnAddCollection(wxCommandEvent &WXUNUSED(evt));

/**
* Event-handler for the Play menu item.
*/
void OnPlayFile(wxCommandEvent &event);

//! Pointer used to ensure that the menu isn't displayed twice.
wxMenu *m_menu;

Expand Down
Loading