~ubuntu-branches/ubuntu/gutsy/kid3/gutsy

« back to all changes in this revision

Viewing changes to kid3/taglibframelist.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Anthony Mercatante
  • Date: 2007-07-01 00:31:03 UTC
  • mfrom: (1.1.5 upstream)
  • Revision ID: james.westby@ubuntu.com-20070701003103-2qownnv49a7jdqm3
Tags: 0.9-0ubuntu1
New upstream release

Show diffs side-by-side

added added

removed removed

Lines of Context:
164
164
public:
165
165
        /**
166
166
         * Constructor.
167
 
         *
168
 
         * @param fl  frame list
169
 
         * @param id  ID of field
170
 
         * @param fld ID3 field
171
167
         */
172
168
        TagLibFieldControl() {}
173
169
 
475
471
 public:
476
472
        /**
477
473
         * Constructor.
478
 
         * @param label label
 
474
         * @param label      label
 
475
         * @param viewButton true to display a View button
479
476
         */
480
477
        explicit TagLibBinFieldControl(const QString& label, bool viewButton = false) :
481
478
        m_label(label), m_viewButton(viewButton) {}
719
716
                                                                                 Q3PtrList<FieldControl> &ctls);
720
717
 
721
718
protected:
722
 
        QVBoxLayout* m_vlayout;
723
 
        QHBoxLayout* m_hlayout;
724
 
        QSpacerItem* m_hspacer;
725
 
        QPushButton* m_okButton;
726
 
        QPushButton* m_cancelButton;
 
719
        QVBoxLayout* m_vlayout;      /**< vertical layout */
 
720
        QHBoxLayout* m_hlayout;      /**< horizontal layout */
 
721
        QSpacerItem* m_hspacer;      /**< horizontal spacer */
 
722
        QPushButton* m_okButton;     /**< OK button */
 
723
        QPushButton* m_cancelButton; /**< Cancel button */
727
724
};
728
725
 
729
726
/**
734
731
 * @param ctls    list with controls to edit fields
735
732
 */
736
733
TagLibEditFrameDialog::TagLibEditFrameDialog(
737
 
        QWidget* parent, const QString &caption, Q3PtrList<FieldControl> &ctls) :
 
734
        QWidget* parent, const QString& caption, Q3PtrList<FieldControl>& ctls) :
738
735
        QDialog(parent, "edit_frame", true)
739
736
{
740
737
        setCaption(caption);
909
906
 */
910
907
void TagLibFrameList::readTags()
911
908
{
912
 
        listbox->clear();
 
909
        s_listbox->clear();
913
910
        if (m_tag) {
914
911
                TagLib::ID3v2::Tag* id3v2Tag;
915
912
                TagLib::Ogg::XiphComment* oggTag;
916
913
                TagLib::APE::Tag* apeTag;
917
914
                if ((id3v2Tag = dynamic_cast<TagLib::ID3v2::Tag*>(m_tag)) != 0) {
918
915
                        const TagLib::ID3v2::FrameList& frameList = id3v2Tag->frameList();
 
916
                        int i = 0;
919
917
                        for (TagLib::ID3v2::FrameList::ConstIterator it = frameList.begin();
920
918
                                         it != frameList.end();
921
919
                                         ++it) {
922
 
                                listbox->insertItem(getId3v2FrameDescription((*it)->frameID()));
 
920
                                new FrameListItem(s_listbox, getId3v2FrameDescription((*it)->frameID()), i++);
923
921
                        }
924
922
                } else if ((oggTag = dynamic_cast<TagLib::Ogg::XiphComment*>(m_tag)) != 0) {
925
923
                        const TagLib::Ogg::FieldListMap& fieldListMap = oggTag->fieldListMap();
 
924
                        int i = 0;
926
925
                        for (TagLib::Ogg::FieldListMap::ConstIterator it = fieldListMap.begin();
927
926
                                         it != fieldListMap.end();
928
927
                                         ++it) {
931
930
                                for (TagLib::StringList::ConstIterator slit = stringList.begin();
932
931
                                                 slit != stringList.end();
933
932
                                                 ++slit) {
934
 
                                        listbox->insertItem(id);
 
933
                                        new FrameListItem(s_listbox, id, i++);
935
934
                                }
936
935
                        }
937
936
                } else if ((apeTag = dynamic_cast<TagLib::APE::Tag*>(m_tag)) != 0) {
938
937
                        const TagLib::APE::ItemListMap& itemListMap = apeTag->itemListMap();
 
938
                        int i = 0;
939
939
                        for (TagLib::APE::ItemListMap::ConstIterator it = itemListMap.begin();
940
940
                                         it != itemListMap.end();
941
941
                                         ++it) {
942
 
                                listbox->insertItem(TStringToQString((*it).first));
 
942
                                new FrameListItem(s_listbox, TStringToQString((*it).first), i++);
943
943
                        }
944
944
                }
 
945
                s_listbox->sort();
945
946
        }
946
947
}
947
948
 
1096
1097
        I18N_NOOP("UTF16"),
1097
1098
        I18N_NOOP("UTF16BE"),
1098
1099
        I18N_NOOP("UTF8"),
1099
 
        I18N_NOOP("UTF16LE"),
1100
1100
        0
1101
1101
};
1102
1102
 
1103
1103
/**
1104
 
 * Edit a text identificatin frame.
 
1104
 * Edit a text identification frame.
1105
1105
 *
1106
1106
 * @param tFrame text identification frame
1107
1107
 * @param id     frame ID
1830
1830
bool TagLibFrameList::editFrame()
1831
1831
{
1832
1832
        bool edited = false;
1833
 
        int selectedIndex = listbox->currentItem();
1834
 
        if (selectedIndex != -1 && m_tag) {
 
1833
        int selectedIndex = s_listbox->currentItem();
 
1834
        int selectedId = getSelectedId();
 
1835
        if (selectedId != -1 && m_tag) {
1835
1836
                TagLib::ID3v2::Tag* id3v2Tag;
1836
1837
                TagLib::Ogg::XiphComment* oggTag;
1837
1838
                TagLib::APE::Tag* apeTag;
1838
1839
                if ((id3v2Tag = dynamic_cast<TagLib::ID3v2::Tag*>(m_tag)) != 0) {
1839
1840
                        const TagLib::ID3v2::FrameList& frameList = id3v2Tag->frameList();
1840
 
                        if (selectedIndex < static_cast<int>(frameList.size())) {
1841
 
                                TagLib::ID3v2::Frame* oldFrame = frameList[selectedIndex];
 
1841
                        if (selectedId < static_cast<int>(frameList.size())) {
 
1842
                                TagLib::ID3v2::Frame* oldFrame = frameList[selectedId];
1842
1843
                                TagLib::ID3v2::Frame* newFrame;
1843
1844
                                if ((newFrame = editId3v2Frame(oldFrame)) != 0) {
1844
1845
                                        id3v2Tag->removeFrame(oldFrame);
1848
1849
                        }
1849
1850
                } else if ((oggTag = dynamic_cast<TagLib::Ogg::XiphComment*>(m_tag)) != 0) {
1850
1851
                        TagLib::String key, value;
1851
 
                        if (getXiphCommentField(*oggTag, selectedIndex, key, value)) {
 
1852
                        if (getXiphCommentField(*oggTag, selectedId, key, value)) {
1852
1853
                                TagLib::String oldValue = value;
1853
1854
                                if (editKeyValueField(key, value)) {
1854
1855
                                        if (!(value == oldValue)) {
1868
1869
                } else if ((apeTag = dynamic_cast<TagLib::APE::Tag*>(m_tag)) != 0) {
1869
1870
                        TagLib::String key;
1870
1871
                        TagLib::APE::Item item;
1871
 
                        if (getApeItem(*apeTag, selectedIndex, key, item)) {
 
1872
                        if (getApeItem(*apeTag, selectedId, key, item)) {
1872
1873
                                TagLib::StringList values = item.toStringList();
1873
1874
                                TagLib::String value = values.size() > 0 ? values.front() : "";
1874
1875
                                TagLib::String oldValue = value;
1885
1886
                readTags(); // refresh listbox
1886
1887
                // select the next item (or the last if it was the last)
1887
1888
                if (selectedIndex >= 0) {
1888
 
                        const int lastIndex = listbox->count() - 1;
 
1889
                        const int lastIndex = s_listbox->count() - 1;
1889
1890
                        if (lastIndex >= 0) {
1890
 
                                listbox->setSelected(
 
1891
                                s_listbox->setSelected(
1891
1892
                                        selectedIndex <= lastIndex ? selectedIndex : lastIndex, true);
 
1893
                                s_listbox->ensureCurrentVisible();
1892
1894
                        }
1893
1895
                }
1894
1896
                if (m_file) {
1895
 
                        m_file->changedV2 = true;
 
1897
                        m_file->markTag2Changed();
1896
1898
                }
1897
1899
        }
1898
1900
        return edited;
1906
1908
bool TagLibFrameList::deleteFrame()
1907
1909
{
1908
1910
        bool deleted = false;
1909
 
        int selectedIndex = listbox->currentItem();
1910
 
        if (selectedIndex != -1 && m_tag) {
 
1911
        int selectedIndex = s_listbox->currentItem();
 
1912
        int selectedId = getSelectedId();
 
1913
        if (selectedId != -1 && m_tag) {
1911
1914
                TagLib::ID3v2::Tag* id3v2Tag;
1912
1915
                TagLib::Ogg::XiphComment* oggTag;
1913
1916
                TagLib::APE::Tag* apeTag;
1914
1917
                if ((id3v2Tag = dynamic_cast<TagLib::ID3v2::Tag*>(m_tag)) != 0) {
1915
1918
                        const TagLib::ID3v2::FrameList& frameList = id3v2Tag->frameList();
1916
 
                        if (selectedIndex < static_cast<int>(frameList.size())) {
1917
 
                                id3v2Tag->removeFrame(frameList[selectedIndex]);
 
1919
                        if (selectedId < static_cast<int>(frameList.size())) {
 
1920
                                id3v2Tag->removeFrame(frameList[selectedId]);
1918
1921
                                deleted = true;
1919
1922
                        }
1920
1923
                } else if ((oggTag = dynamic_cast<TagLib::Ogg::XiphComment*>(m_tag)) != 0) {
1921
1924
                        TagLib::String key, value;
1922
 
                        if (getXiphCommentField(*oggTag, selectedIndex, key, value)) {
 
1925
                        if (getXiphCommentField(*oggTag, selectedId, key, value)) {
1923
1926
#ifdef TAGLIB_XIPHCOMMENT_REMOVEFIELD_CRASHES
1924
1927
                                oggTag->removeField(key);
1925
1928
#else
1933
1936
                } else if ((apeTag = dynamic_cast<TagLib::APE::Tag*>(m_tag)) != 0) {
1934
1937
                        TagLib::String key;
1935
1938
                        TagLib::APE::Item item;
1936
 
                        if (getApeItem(*apeTag, selectedIndex, key, item)) {
 
1939
                        if (getApeItem(*apeTag, selectedId, key, item)) {
1937
1940
                                apeTag->removeItem(key);
1938
1941
                                deleted = true;
1939
1942
                        }
1942
1945
                        readTags(); // refresh listbox
1943
1946
                        // select the next item (or the last if it was the last)
1944
1947
                        if (selectedIndex >= 0) {
1945
 
                                const int lastIndex = listbox->count() - 1;
 
1948
                                const int lastIndex = s_listbox->count() - 1;
1946
1949
                                if (lastIndex >= 0) {
1947
 
                                        listbox->setSelected(
 
1950
                                        s_listbox->setSelected(
1948
1951
                                                selectedIndex <= lastIndex ? selectedIndex : lastIndex, true);
 
1952
                                        s_listbox->ensureCurrentVisible();
1949
1953
                                }
1950
1954
                        }
1951
1955
                        if (m_file) {
1952
 
                                m_file->changedV2 = true;
 
1956
                                m_file->markTag2Changed();
1953
1957
                        }
1954
1958
                        return true;
1955
1959
                }
2048
2052
                                if (newFrame) {
2049
2053
                                        id3v2Tag->addFrame(newFrame);
2050
2054
                                        added = true;
 
2055
                                        int frameIndex = id3v2Tag->frameList().size() - 1;
2051
2056
                                        readTags(); // refresh listbox
2052
 
                                        const int lastIndex = listbox->count() - 1;
2053
 
                                        if (lastIndex >= 0) {
2054
 
                                                listbox->setSelected(lastIndex, true);
2055
 
                                        }
 
2057
                                        setSelectedId(frameIndex);
 
2058
                                        s_listbox->ensureCurrentVisible();
2056
2059
                                }
2057
2060
                        }
2058
2061
                } else if ((oggTag = dynamic_cast<TagLib::Ogg::XiphComment*>(m_tag)) != 0) {
2065
2068
                                oggTag->addField(key, value);
2066
2069
                                added = true;
2067
2070
                                readTags(); // refresh listbox
2068
 
                                Q3ListBoxItem* lbi = listbox->findItem(m_selectedName);
 
2071
                                Q3ListBoxItem* lbi = s_listbox->findItem(m_selectedName);
2069
2072
                                if (lbi) {
2070
 
                                        listbox->setSelected(lbi, true);
 
2073
                                        s_listbox->setSelected(lbi, true);
 
2074
                                        s_listbox->ensureCurrentVisible();
2071
2075
                                }
2072
2076
                        }
2073
2077
                } else if ((apeTag = dynamic_cast<TagLib::APE::Tag*>(m_tag)) != 0) {
2080
2084
                                apeTag->addValue(key, value, true);
2081
2085
                                added = true;
2082
2086
                                readTags(); // refresh listbox
2083
 
                                Q3ListBoxItem* lbi = listbox->findItem(m_selectedName);
 
2087
                                Q3ListBoxItem* lbi = s_listbox->findItem(m_selectedName);
2084
2088
                                if (lbi) {
2085
 
                                        listbox->setSelected(lbi, true);
 
2089
                                        s_listbox->setSelected(lbi, true);
 
2090
                                        s_listbox->ensureCurrentVisible();
2086
2091
                                }
2087
2092
                        }
2088
2093
                }
2089
2094
                if (added) {
2090
2095
                        if (m_file) {
2091
 
                                m_file->changedV2 = true;
 
2096
                                m_file->markTag2Changed();
2092
2097
                        }
2093
2098
                }
2094
2099
        }
2186
2191
                        bool ok = false;
2187
2192
                        QString res = QInputDialog::getItem(
2188
2193
                                i18n("Add Frame"),
2189
 
                                i18n("Select the frame ID"), lst, 0, true, &ok);
 
2194
                                i18n("Select the frame ID")
 
2195
#if QT_VERSION >= 0x040000
 
2196
                                // the dialog is too small in Qt4
 
2197
                                + "                                     "
 
2198
#endif
 
2199
                                , lst, 0, true, &ok);
2190
2200
                        if (ok) {
2191
2201
                                m_selectedName = res;
2192
2202
                                return 0; // just used by addFrame()
2204
2214
bool TagLibFrameList::copyFrame()
2205
2215
{
2206
2216
        bool copied = false;
2207
 
        int selectedIndex = listbox->currentItem();
2208
 
        if (selectedIndex != -1 && m_tag) {
 
2217
        int selectedId = getSelectedId();
 
2218
        if (selectedId != -1 && m_tag) {
2209
2219
                TagLib::ID3v2::Tag* id3v2Tag;
2210
2220
                TagLib::Ogg::XiphComment* oggTag;
2211
2221
                TagLib::APE::Tag* apeTag;
2212
2222
                if ((id3v2Tag = dynamic_cast<TagLib::ID3v2::Tag*>(m_tag)) != 0) {
2213
2223
                        const TagLib::ID3v2::FrameList& frameList = id3v2Tag->frameList();
2214
 
                        if (selectedIndex < static_cast<int>(frameList.size())) {
2215
 
                                m_copyData = frameList[selectedIndex]->render();
 
2224
                        if (selectedId < static_cast<int>(frameList.size())) {
 
2225
                                m_copyData = frameList[selectedId]->render();
2216
2226
                                copied = true;
2217
2227
                        }
2218
2228
                } else if ((oggTag = dynamic_cast<TagLib::Ogg::XiphComment*>(m_tag)) != 0) {
2219
2229
                        TagLib::String key, value;
2220
 
                        if (getXiphCommentField(*oggTag, selectedIndex, key, value)) {
 
2230
                        if (getXiphCommentField(*oggTag, selectedId, key, value)) {
2221
2231
                                m_copyKey = key;
2222
2232
                                m_copyValue = value;
2223
2233
                                copied = true;
2225
2235
                } else if ((apeTag = dynamic_cast<TagLib::APE::Tag*>(m_tag)) != 0) {
2226
2236
                        TagLib::String key;
2227
2237
                        TagLib::APE::Item item;
2228
 
                        if (getApeItem(*apeTag, selectedIndex, key, item)) {
 
2238
                        if (getApeItem(*apeTag, selectedId, key, item)) {
2229
2239
                                m_copyKey = key;
2230
2240
                                TagLib::StringList values = item.toStringList();
2231
2241
                                m_copyValue = values.size() > 0 ? values.front() : "";
2271
2281
                }
2272
2282
        }
2273
2283
        if (pasted && m_file) {
2274
 
                m_file->changedV2 = true;
 
2284
                m_file->markTag2Changed();
2275
2285
        }
2276
2286
        return pasted;
2277
2287
}