Beispiel #1
0
// Find the text of the list control item at the given column
wxString wxListCtrlGetItemTextColumn(wxListCtrl& listCtrl, long item, int col)
{
    wxListItem listItem;
    listItem.m_mask = wxLIST_MASK_TEXT;
    listItem.m_itemId = item;
    listItem.m_col = col;

    if (listCtrl.GetItem(listItem))
        return listItem.m_text;
    else
        return wxEmptyString;
}
Beispiel #2
0
void ConvertViewCtrlToTrackData(const wxListCtrl &listctrl, const std::map< wxString, long > &mapping, std::vector<lfmt::TrackData> &tracklist, wxDateTime offset)
{
    auto row_count = listctrl.GetItemCount();

    if (row_count < 1)
        return;

    // grab column indices from string-long-map which we have just for purpose of dynamic indices (ie. changing column order is easy)
    auto idx_artist = mapping.find("Artist")->second;
    auto idx_tname  = mapping.find("Trackname")->second;
    auto idx_album  = mapping.find("Album")->second;
    auto idx_time  = mapping.find("Time")->second;

    wxDateTime last_time = offset;

    // last track on the list is the most recentry track that was listened to;
    // moving up the list successive tracks will get earlier times
    for (int row = row_count-1; row >= 0; --row)
    {
        lfmt::TrackData td;

        // is there a better way of getting the info out of the listviewctrl?
        // it's questionable if I would have gotten it without the wxforum :(
        wxListItem item;
        item.SetId(row);
        item.SetMask(wxLIST_MASK_TEXT);

        // "unrolled loop" for all columns
        item.SetColumn(idx_artist);
        listctrl.GetItem(item);
        td.artist = item.GetText();

        item.SetColumn(idx_tname);
        listctrl.GetItem(item);
        td.trackname = item.GetText();

        item.SetColumn(idx_album);
        listctrl.GetItem(item);
        td.album = item.GetText();

        td.timestamp = last_time.GetTicks(); // set time *before* calculating the descendant
        item.SetColumn(idx_time);
        listctrl.GetItem(item);
        {
            // now calculate 'last_time' offset according to playtime of the current track
            // defaults to 3 minutes if we don't know the track's length
            wxArrayString time_str = wxStringTokenize(item.GetText(), ":");
            long minutes, seconds;
            bool success = true;
            success &= time_str[0].ToLong(&minutes);
            success &= time_str[1].ToLong(&seconds);

            if (success)
                last_time -= wxTimeSpan(0, minutes, seconds);
            else
            {
                wxLogWarning("Could not parse timespan " + item.GetText() + ". Assuming track length of 3 minutes.");
                last_time -= wxTimeSpan(0, 3, 0);
            }
        }

        tracklist.push_back(td);

        wxLogDebug("Converted track " + td.ToString() + " from row %d.", row);
    }
}