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

« back to all changes in this revision

Viewing changes to kid3/mp3framelist.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Sarah Hobbs
  • Date: 2006-07-14 12:25:16 UTC
  • mfrom: (1.1.3 upstream)
  • Revision ID: james.westby@ubuntu.com-20060714122516-p2wk0iyzumu6jx42
Tags: 0.7-1ubuntu1
Merge from debian unstable.

Show diffs side-by-side

added added

removed removed

Lines of Context:
616
616
 * Constructor.
617
617
 */
618
618
 
619
 
Mp3FrameList::Mp3FrameList() : tags(0), selected_enc(ID3TE_NONE)
 
619
Mp3FrameList::Mp3FrameList() : tags(0), selected_enc(ID3TE_NONE),
 
620
                                                                                                                         m_copyFrame(0)
620
621
{
621
622
        fieldcontrols.setAutoDelete(TRUE);
622
623
}
624
625
/**
625
626
 * Destructor.
626
627
 */
627
 
Mp3FrameList::~Mp3FrameList() {}
 
628
Mp3FrameList::~Mp3FrameList()
 
629
{
 
630
        if (m_copyFrame) {
 
631
                delete m_copyFrame;
 
632
        }
 
633
}
628
634
 
629
635
/**
630
636
 * Fill listbox with frame descriptions.
737
743
}
738
744
 
739
745
/**
740
 
 * Create dialog to edit the selected frame and update the fields if Ok is
 
746
 * Create dialog to edit a frame and update the fields if Ok is
741
747
 * returned.
742
748
 *
 
749
 * @param frame frame to edit
 
750
 *
743
751
 * @return TRUE if Ok selected in dialog.
744
752
 */
745
 
 
746
 
bool Mp3FrameList::editFrame(void)
 
753
bool Mp3FrameList::editFrame(ID3_Frame* frame)
747
754
{
748
755
        bool result = FALSE;
749
 
        ID3_Frame *frame = getSelectedFrame();
750
 
        if (frame) {
751
 
                ID3_Frame::Iterator* iter = frame->CreateIterator();
752
 
                ID3_Field *field;
753
 
                while ((field = iter->GetNext()) != NULL) {
754
 
                        ID3_FieldID id = field->GetID();
755
 
                        ID3_FieldType type = field->GetType();
756
 
                        if (type == ID3FTY_INTEGER) {
757
 
                                if (id == ID3FN_TEXTENC) {
758
 
                                        static const char *strlst[] = {
759
 
                                                I18N_NOOP("ISO-8859-1"),
760
 
                                                I18N_NOOP("Unicode"),
761
 
                                                I18N_NOOP("UTF16BE"),
762
 
                                                I18N_NOOP("UTF8"),
763
 
                                                NULL
764
 
                                        };
765
 
                                        IntComboBoxControl *cbox =
766
 
                                                new IntComboBoxControl(this, id, field, strlst);
767
 
                                        if (cbox) {
768
 
                                                fieldcontrols.append(cbox);
769
 
                                        }
770
 
                                }
771
 
                                else if (id == ID3FN_PICTURETYPE) {
772
 
                                        static const char *strlst[] = {
773
 
                                                I18N_NOOP("Other"),
774
 
                                                I18N_NOOP("32x32 pixels PNG file icon"),
775
 
                                                I18N_NOOP("Other file icon"),
776
 
                                                I18N_NOOP("Cover (front)"),
777
 
                                                I18N_NOOP("Cover (back)"),
778
 
                                                I18N_NOOP("Leaflet page"),
779
 
                                                I18N_NOOP("Media"),
780
 
                                                I18N_NOOP("Lead artist/lead performer/soloist"),
781
 
                                                I18N_NOOP("Artist/performer"),
782
 
                                                I18N_NOOP("Conductor"),
783
 
                                                I18N_NOOP("Band/Orchestra"),
784
 
                                                I18N_NOOP("Composer"),
785
 
                                                I18N_NOOP("Lyricist/text writer"),
786
 
                                                I18N_NOOP("Recording Location"),
787
 
                                                I18N_NOOP("During recording"),
788
 
                                                I18N_NOOP("During performance"),
789
 
                                                I18N_NOOP("Movie/video screen capture"),
790
 
                                                I18N_NOOP("A bright coloured fish"),
791
 
                                                I18N_NOOP("Illustration"),
792
 
                                                I18N_NOOP("Band/artist logotype"),
793
 
                                                I18N_NOOP("Publisher/Studio logotype"),
794
 
                                                NULL
795
 
                                        };
796
 
                                        IntComboBoxControl *cbox =
797
 
                                                new IntComboBoxControl(this, id, field, strlst);
798
 
                                        if (cbox) {
799
 
                                                fieldcontrols.append(cbox);
800
 
                                        }
801
 
                                }
802
 
                                else if (id == ID3FN_TIMESTAMPFORMAT) {
803
 
                                        static const char *strlst[] = {
804
 
                                                I18N_NOOP("Other"),
805
 
                                                I18N_NOOP("MPEG frames as unit"),
806
 
                                                I18N_NOOP("Milliseconds as unit"),
807
 
                                                NULL
808
 
                                        };
809
 
                                        IntComboBoxControl *cbox =
810
 
                                                new IntComboBoxControl(this, id, field, strlst);
811
 
                                        if (cbox) {
812
 
                                                fieldcontrols.append(cbox);
813
 
                                        }
814
 
                                }
815
 
                                else if (id == ID3FN_CONTENTTYPE) {
816
 
                                        static const char *strlst[] = {
817
 
                                                I18N_NOOP("Other"),
818
 
                                                I18N_NOOP("Lyrics"),
819
 
                                                I18N_NOOP("Text transcription"),
820
 
                                                I18N_NOOP("Movement/part name"),
821
 
                                                I18N_NOOP("Events"),
822
 
                                                I18N_NOOP("Chord"),
823
 
                                                I18N_NOOP("Trivia/pop up"),
824
 
                                                NULL
825
 
                                        };
826
 
                                        IntComboBoxControl *cbox =
827
 
                                                new IntComboBoxControl(this, id, field, strlst);
828
 
                                        if (cbox) {
829
 
                                                fieldcontrols.append(cbox);
830
 
                                        }
831
 
                                }
832
 
                                else {
833
 
                                        IntFieldControl *intctl =
834
 
                                                new IntFieldControl(this, id, field);
835
 
                                        if (intctl) {
836
 
                                                fieldcontrols.append(intctl);
837
 
                                        }
838
 
                                }
839
 
                        }
840
 
                        else if (type == ID3FTY_BINARY) {
841
 
                                BinFieldControl *binctl =
842
 
                                        new BinFieldControl(this, id, field);
843
 
                                if (binctl) {
844
 
                                        fieldcontrols.append(binctl);
845
 
                                }
846
 
                        }
847
 
                        else if (type == ID3FTY_TEXTSTRING) {
848
 
                                ID3_TextEnc enc = field->GetEncoding();
849
 
                                if (id == ID3FN_TEXT ||
 
756
        ID3_Frame::Iterator* iter = frame->CreateIterator();
 
757
        ID3_Field *field;
 
758
        while ((field = iter->GetNext()) != NULL) {
 
759
                ID3_FieldID id = field->GetID();
 
760
                ID3_FieldType type = field->GetType();
 
761
                if (type == ID3FTY_INTEGER) {
 
762
                        if (id == ID3FN_TEXTENC) {
 
763
                                static const char *strlst[] = {
 
764
                                        I18N_NOOP("ISO-8859-1"),
 
765
                                        I18N_NOOP("Unicode"),
 
766
                                        I18N_NOOP("UTF16BE"),
 
767
                                        I18N_NOOP("UTF8"),
 
768
                                        NULL
 
769
                                };
 
770
                                IntComboBoxControl *cbox =
 
771
                                        new IntComboBoxControl(this, id, field, strlst);
 
772
                                if (cbox) {
 
773
                                        fieldcontrols.append(cbox);
 
774
                                }
 
775
                        }
 
776
                        else if (id == ID3FN_PICTURETYPE) {
 
777
                                static const char *strlst[] = {
 
778
                                        I18N_NOOP("Other"),
 
779
                                        I18N_NOOP("32x32 pixels PNG file icon"),
 
780
                                        I18N_NOOP("Other file icon"),
 
781
                                        I18N_NOOP("Cover (front)"),
 
782
                                        I18N_NOOP("Cover (back)"),
 
783
                                        I18N_NOOP("Leaflet page"),
 
784
                                        I18N_NOOP("Media"),
 
785
                                        I18N_NOOP("Lead artist/lead performer/soloist"),
 
786
                                        I18N_NOOP("Artist/performer"),
 
787
                                        I18N_NOOP("Conductor"),
 
788
                                        I18N_NOOP("Band/Orchestra"),
 
789
                                        I18N_NOOP("Composer"),
 
790
                                        I18N_NOOP("Lyricist/text writer"),
 
791
                                        I18N_NOOP("Recording Location"),
 
792
                                        I18N_NOOP("During recording"),
 
793
                                        I18N_NOOP("During performance"),
 
794
                                        I18N_NOOP("Movie/video screen capture"),
 
795
                                        I18N_NOOP("A bright coloured fish"),
 
796
                                        I18N_NOOP("Illustration"),
 
797
                                        I18N_NOOP("Band/artist logotype"),
 
798
                                        I18N_NOOP("Publisher/Studio logotype"),
 
799
                                        NULL
 
800
                                };
 
801
                                IntComboBoxControl *cbox =
 
802
                                        new IntComboBoxControl(this, id, field, strlst);
 
803
                                if (cbox) {
 
804
                                        fieldcontrols.append(cbox);
 
805
                                }
 
806
                        }
 
807
                        else if (id == ID3FN_TIMESTAMPFORMAT) {
 
808
                                static const char *strlst[] = {
 
809
                                        I18N_NOOP("Other"),
 
810
                                        I18N_NOOP("MPEG frames as unit"),
 
811
                                        I18N_NOOP("Milliseconds as unit"),
 
812
                                        NULL
 
813
                                };
 
814
                                IntComboBoxControl *cbox =
 
815
                                        new IntComboBoxControl(this, id, field, strlst);
 
816
                                if (cbox) {
 
817
                                        fieldcontrols.append(cbox);
 
818
                                }
 
819
                        }
 
820
                        else if (id == ID3FN_CONTENTTYPE) {
 
821
                                static const char *strlst[] = {
 
822
                                        I18N_NOOP("Other"),
 
823
                                        I18N_NOOP("Lyrics"),
 
824
                                        I18N_NOOP("Text transcription"),
 
825
                                        I18N_NOOP("Movement/part name"),
 
826
                                        I18N_NOOP("Events"),
 
827
                                        I18N_NOOP("Chord"),
 
828
                                        I18N_NOOP("Trivia/pop up"),
 
829
                                        NULL
 
830
                                };
 
831
                                IntComboBoxControl *cbox =
 
832
                                        new IntComboBoxControl(this, id, field, strlst);
 
833
                                if (cbox) {
 
834
                                        fieldcontrols.append(cbox);
 
835
                                }
 
836
                        }
 
837
                        else {
 
838
                                IntFieldControl *intctl =
 
839
                                        new IntFieldControl(this, id, field);
 
840
                                if (intctl) {
 
841
                                        fieldcontrols.append(intctl);
 
842
                                }
 
843
                        }
 
844
                }
 
845
                else if (type == ID3FTY_BINARY) {
 
846
                        BinFieldControl *binctl =
 
847
                                new BinFieldControl(this, id, field);
 
848
                        if (binctl) {
 
849
                                fieldcontrols.append(binctl);
 
850
                        }
 
851
                }
 
852
                else if (type == ID3FTY_TEXTSTRING) {
 
853
                        ID3_TextEnc enc = field->GetEncoding();
 
854
                        if (id == ID3FN_TEXT ||
850
855
                                        // (ID3TE_IS_DOUBLE_BYTE_ENC(enc))
851
856
                                        enc == ID3TE_UTF16 || enc == ID3TE_UTF16BE) {
852
 
                                        // Large textedit for text fields
853
 
                                        TextFieldControl *textctl =
854
 
                                                new TextFieldControl(this, id, field);
855
 
                                        if (textctl) {
856
 
                                                fieldcontrols.append(textctl);
857
 
                                        }
 
857
                                // Large textedit for text fields
 
858
                                TextFieldControl *textctl =
 
859
                                        new TextFieldControl(this, id, field);
 
860
                                if (textctl) {
 
861
                                        fieldcontrols.append(textctl);
858
862
                                }
859
 
                                else {
860
 
                                        LineFieldControl *textctl =
861
 
                                                new LineFieldControl(this, id, field);
862
 
                                        if (textctl) {
863
 
                                                fieldcontrols.append(textctl);
864
 
                                        }
 
863
                        }
 
864
                        else {
 
865
                                LineFieldControl *textctl =
 
866
                                        new LineFieldControl(this, id, field);
 
867
                                if (textctl) {
 
868
                                        fieldcontrols.append(textctl);
865
869
                                }
866
870
                        }
867
871
                }
 
872
        }
868
873
#ifdef WIN32
869
 
                /* allocated in Windows DLL => must be freed in the same DLL */
870
 
                ID3TagIterator_Delete(reinterpret_cast<ID3TagIterator*>(iter));
 
874
        /* allocated in Windows DLL => must be freed in the same DLL */
 
875
        ID3TagIterator_Delete(reinterpret_cast<ID3TagIterator*>(iter));
871
876
#else
872
 
                delete iter;
 
877
        delete iter;
873
878
#endif
874
 
                const char *idstr = getIdString(frame->GetID());
875
 
                QString caption = idstr ? i18n(idstr) : QString(frame->GetTextID());
876
 
                EditMp3FrameDialog *dialog =
877
 
                        new EditMp3FrameDialog(NULL, caption, fieldcontrols);
878
 
                if (dialog && dialog->exec() == QDialog::Accepted) {
879
 
                        FieldControl *fld_ctl = fieldcontrols.first();
880
 
                        // will be set if there is an encoding selector
881
 
                        setSelectedEncoding(ID3TE_NONE);
882
 
                        while (fld_ctl != NULL) {
883
 
                                fld_ctl->updateTag();
884
 
                                fld_ctl = fieldcontrols.next();
885
 
                        }
886
 
                        if (m_file) {
887
 
                                m_file->changedV2 = TRUE;
888
 
                        }
889
 
                        result = TRUE;
890
 
                }
891
 
                fieldcontrols.clear();
 
879
        const char *idstr = getIdString(frame->GetID());
 
880
        QString caption = idstr ? i18n(idstr) : QString(frame->GetTextID());
 
881
        EditMp3FrameDialog *dialog =
 
882
                new EditMp3FrameDialog(NULL, caption, fieldcontrols);
 
883
        if (dialog && dialog->exec() == QDialog::Accepted) {
 
884
                FieldControl *fld_ctl = fieldcontrols.first();
 
885
                // will be set if there is an encoding selector
 
886
                setSelectedEncoding(ID3TE_NONE);
 
887
                while (fld_ctl != NULL) {
 
888
                        fld_ctl->updateTag();
 
889
                        fld_ctl = fieldcontrols.next();
 
890
                }
 
891
                if (m_file) {
 
892
                        m_file->changedV2 = TRUE;
 
893
                }
 
894
                result = TRUE;
892
895
        }
 
896
        fieldcontrols.clear();
893
897
        return result;
894
898
}
895
899
 
896
900
/**
 
901
 * Create dialog to edit the selected frame and update the fields if Ok is
 
902
 * returned.
 
903
 *
 
904
 * @return TRUE if Ok selected in dialog.
 
905
 */
 
906
 
 
907
bool Mp3FrameList::editFrame(void)
 
908
{
 
909
        ID3_Frame* frame = getSelectedFrame();
 
910
        if (frame) {
 
911
                return editFrame(frame);
 
912
        }
 
913
        return false;
 
914
}
 
915
 
 
916
/**
897
917
 * Delete selected frame.
898
918
 *
899
919
 * @return FALSE if frame not found.
928
948
 * Add a new frame.
929
949
 *
930
950
 * @param frameId ID of frame to add
 
951
 * @param edit    true to edit frame after adding it
931
952
 * @return TRUE if frame added.
932
953
 */
933
954
 
934
 
bool Mp3FrameList::addFrame(int frameId)
 
955
bool Mp3FrameList::addFrame(int frameId, bool edit)
935
956
{
936
957
        if (frameId < 0 || frameId > ID3FID_LASTFRAMEID) {
937
958
                return false;
944
965
        ID3_Frame *frame = new ID3_Frame(id);
945
966
        if (frame) {
946
967
                if (tags) {
 
968
                        if (edit && !editFrame(frame)) {
 
969
                                delete frame;
 
970
                                return false;
 
971
                        }
947
972
                        tags->AttachFrame(frame);
948
973
                        readTags(); // refresh listbox
949
974
                        const int lastIndex = listbox->count() - 1;
950
975
                        if (lastIndex >= 0) {
951
976
                                listbox->setSelected(lastIndex, true);
952
977
                        }
953
 
                }
954
 
                if (m_file) {
955
 
                        m_file->changedV2 = TRUE;
956
 
                }
957
 
                return TRUE;
 
978
                        if (m_file) {
 
979
                                m_file->changedV2 = TRUE;
 
980
                        }
 
981
                        return TRUE;
 
982
                }
 
983
                delete frame;
958
984
        }
959
985
        return FALSE;
960
986
}
1163
1189
        }
1164
1190
        return -1;
1165
1191
}
 
1192
 
 
1193
/**
 
1194
 * Copy the selected frame to the copy buffer.
 
1195
 *
 
1196
 * @return true if frame copied.
 
1197
 */
 
1198
bool Mp3FrameList::copyFrame() {
 
1199
        ID3_Frame *frame = getSelectedFrame();
 
1200
        if (frame) {
 
1201
                if (m_copyFrame) {
 
1202
                        delete m_copyFrame;
 
1203
                }
 
1204
                m_copyFrame = new ID3_Frame(*frame);
 
1205
                return true;
 
1206
        }
 
1207
        return false;
 
1208
}
 
1209
 
 
1210
/**
 
1211
 * Paste the selected frame from the copy buffer.
 
1212
 *
 
1213
 * @return true if frame pasted.
 
1214
 */
 
1215
bool Mp3FrameList::pasteFrame() {
 
1216
        if (m_copyFrame && tags) {
 
1217
                ID3_Frame* frame = new ID3_Frame(*m_copyFrame);
 
1218
                if (frame) {
 
1219
                        tags->AttachFrame(frame);
 
1220
                        if (m_file) {
 
1221
                                m_file->changedV2 = true;
 
1222
                        }
 
1223
                        return true;
 
1224
                }
 
1225
        }
 
1226
        return false;
 
1227
}