generic: import libkcddb and libkcompactdics

This commit is contained in:
Ivailo Monev 2015-09-03 22:21:19 +00:00
parent f43cb534f3
commit a40952a3bc
165 changed files with 27099 additions and 0 deletions

View file

@ -67,6 +67,7 @@ set(cmakeFiles
FindLinuxWirelesstools.cmake
FindMsgfmt.cmake
FindMusicBrainz.cmake
FindMusicBrainz5.cmake
FindMySQL.cmake
FindNetworkManager.cmake
FindOggVorbis.cmake

View file

@ -0,0 +1,32 @@
# Module to find the musicbrainz-4 library
#
# It defines
# MUSICBRAINZ5_INCLUDE_DIRS - the include dirs
# MUSICBRAINZ5_LIBRARIES - the required libraries
# MUSICBRAINZ5_FOUND - true if both of the above have been found
# Copyright (c) 2006,2007 Laurent Montel, <montel@kde.org>
#
# Redistribution and use is allowed according to the terms of the BSD license.
# For details see the accompanying COPYING-CMAKE-SCRIPTS file.
if(MUSICBRAINZ5_INCLUDE_DIRS AND MUSICBRAINZ5_LIBRARIES)
set(MUSICBRAINZ5_FIND_QUIETLY TRUE)
endif(MUSICBRAINZ5_INCLUDE_DIRS AND MUSICBRAINZ5_LIBRARIES)
IF (NOT WIN32)
# use pkg-config to get the directories and then use these values
# in the FIND_PATH() and FIND_LIBRARY() calls
find_package(PkgConfig)
PKG_SEARCH_MODULE( MUSICBRAINZ5 libmusicbrainz5 )
ELSE (NOT WIN32)
FIND_PATH( MUSICBRAINZ5_INCLUDE_DIRS musicbrainz5/Disc.h )
FIND_LIBRARY( MUSICBRAINZ5_LIBRARIES NAMES musicbrainz5 )
ENDIF (NOT WIN32)
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args( MusicBrainz5 DEFAULT_MSG
MUSICBRAINZ5_INCLUDE_DIRS MUSICBRAINZ5_LIBRARIES)
MARK_AS_ADVANCED(MUSICBRAINZ5_INCLUDE_DIRS MUSICBRAINZ5_LIBRARIES)

43
libkcddb/CMakeLists.txt Normal file
View file

@ -0,0 +1,43 @@
project(libkcddb)
include_directories(
${CMAKE_CURRENT_BINARY_DIR}
${CMAKE_CURRENT_SOURCE_DIR}
${QT_INCLUDES}
${KDE4_INCLUDES}
)
macro_optional_find_package(MusicBrainz5)
macro_log_feature(MUSICBRAINZ5_FOUND
"MusicBrainz5"
"A library that provides access to metadata lookup on the MusicBrainz server"
"http://www.musicbrainz.org"
FALSE
""
"Music metadata lookup for KDE multimedia applications through libkcddb. You need version 5.x of libmusicbrainz"
)
if(MUSICBRAINZ5_FOUND)
set(HAVE_MUSICBRAINZ5 1)
include_directories(${MUSICBRAINZ5_INCLUDE_DIRS})
set(libmusicbrainz_SRCS ${libmusicbrainz_SRCS}
musicbrainz/musicbrainzlookup.cpp
musicbrainz/asyncmusicbrainzlookup.cpp)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${KDE4_ENABLE_EXCEPTIONS}")
else(MUSICBRAINZ5_FOUND)
set(HAVE_MUSICBRAINZ5 0)
set(libmusicbrainz_SRCS)
endif(MUSICBRAINZ5_FOUND)
configure_file(
${CMAKE_CURRENT_SOURCE_DIR}/config-musicbrainz.h.cmake
${CMAKE_CURRENT_BINARY_DIR}/config-musicbrainz.h
)
if(ENABLE_TESTING)
add_subdirectory( test )
endif()
add_subdirectory( kcmcddb )
add_subdirectory( libkcddb )

346
libkcddb/COPYING Normal file
View file

@ -0,0 +1,346 @@
NOTE! The GPL below is copyrighted by the Free Software Foundation, but
the instance of code that it refers to (the kde programs) are copyrighted
by the authors who actually wrote it.
---------------------------------------------------------------------------
GNU GENERAL PUBLIC LICENSE
Version 2, June 1991
Copyright (C) 1989, 1991 Free Software Foundation, Inc.
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
Preamble
The licenses for most software are designed to take away your
freedom to share and change it. By contrast, the GNU General Public
License is intended to guarantee your freedom to share and change free
software--to make sure the software is free for all its users. This
General Public License applies to most of the Free Software
Foundation's software and to any other program whose authors commit to
using it. (Some other Free Software Foundation software is covered by
the GNU Library General Public License instead.) You can apply it to
your programs, too.
When we speak of free software, we are referring to freedom, not
price. Our General Public Licenses are designed to make sure that you
have the freedom to distribute copies of free software (and charge for
this service if you wish), that you receive source code or can get it
if you want it, that you can change the software or use pieces of it
in new free programs; and that you know you can do these things.
To protect your rights, we need to make restrictions that forbid
anyone to deny you these rights or to ask you to surrender the rights.
These restrictions translate to certain responsibilities for you if you
distribute copies of the software, or if you modify it.
For example, if you distribute copies of such a program, whether
gratis or for a fee, you must give the recipients all the rights that
you have. You must make sure that they, too, receive or can get the
source code. And you must show them these terms so they know their
rights.
We protect your rights with two steps: (1) copyright the software, and
(2) offer you this license which gives you legal permission to copy,
distribute and/or modify the software.
Also, for each author's protection and ours, we want to make certain
that everyone understands that there is no warranty for this free
software. If the software is modified by someone else and passed on, we
want its recipients to know that what they have is not the original, so
that any problems introduced by others will not reflect on the original
authors' reputations.
Finally, any free program is threatened constantly by software
patents. We wish to avoid the danger that redistributors of a free
program will individually obtain patent licenses, in effect making the
program proprietary. To prevent this, we have made it clear that any
patent must be licensed for everyone's free use or not licensed at all.
The precise terms and conditions for copying, distribution and
modification follow.
GNU GENERAL PUBLIC LICENSE
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
0. This License applies to any program or other work which contains
a notice placed by the copyright holder saying it may be distributed
under the terms of this General Public License. The "Program", below,
refers to any such program or work, and a "work based on the Program"
means either the Program or any derivative work under copyright law:
that is to say, a work containing the Program or a portion of it,
either verbatim or with modifications and/or translated into another
language. (Hereinafter, translation is included without limitation in
the term "modification".) Each licensee is addressed as "you".
Activities other than copying, distribution and modification are not
covered by this License; they are outside its scope. The act of
running the Program is not restricted, and the output from the Program
is covered only if its contents constitute a work based on the
Program (independent of having been made by running the Program).
Whether that is true depends on what the Program does.
1. You may copy and distribute verbatim copies of the Program's
source code as you receive it, in any medium, provided that you
conspicuously and appropriately publish on each copy an appropriate
copyright notice and disclaimer of warranty; keep intact all the
notices that refer to this License and to the absence of any warranty;
and give any other recipients of the Program a copy of this License
along with the Program.
You may charge a fee for the physical act of transferring a copy, and
you may at your option offer warranty protection in exchange for a fee.
2. You may modify your copy or copies of the Program or any portion
of it, thus forming a work based on the Program, and copy and
distribute such modifications or work under the terms of Section 1
above, provided that you also meet all of these conditions:
a) You must cause the modified files to carry prominent notices
stating that you changed the files and the date of any change.
b) You must cause any work that you distribute or publish, that in
whole or in part contains or is derived from the Program or any
part thereof, to be licensed as a whole at no charge to all third
parties under the terms of this License.
c) If the modified program normally reads commands interactively
when run, you must cause it, when started running for such
interactive use in the most ordinary way, to print or display an
announcement including an appropriate copyright notice and a
notice that there is no warranty (or else, saying that you provide
a warranty) and that users may redistribute the program under
these conditions, and telling the user how to view a copy of this
License. (Exception: if the Program itself is interactive but
does not normally print such an announcement, your work based on
the Program is not required to print an announcement.)
These requirements apply to the modified work as a whole. If
identifiable sections of that work are not derived from the Program,
and can be reasonably considered independent and separate works in
themselves, then this License, and its terms, do not apply to those
sections when you distribute them as separate works. But when you
distribute the same sections as part of a whole which is a work based
on the Program, the distribution of the whole must be on the terms of
this License, whose permissions for other licensees extend to the
entire whole, and thus to each and every part regardless of who wrote it.
Thus, it is not the intent of this section to claim rights or contest
your rights to work written entirely by you; rather, the intent is to
exercise the right to control the distribution of derivative or
collective works based on the Program.
In addition, mere aggregation of another work not based on the Program
with the Program (or with a work based on the Program) on a volume of
a storage or distribution medium does not bring the other work under
the scope of this License.
3. You may copy and distribute the Program (or a work based on it,
under Section 2) in object code or executable form under the terms of
Sections 1 and 2 above provided that you also do one of the following:
a) Accompany it with the complete corresponding machine-readable
source code, which must be distributed under the terms of Sections
1 and 2 above on a medium customarily used for software interchange; or,
b) Accompany it with a written offer, valid for at least three
years, to give any third party, for a charge no more than your
cost of physically performing source distribution, a complete
machine-readable copy of the corresponding source code, to be
distributed under the terms of Sections 1 and 2 above on a medium
customarily used for software interchange; or,
c) Accompany it with the information you received as to the offer
to distribute corresponding source code. (This alternative is
allowed only for noncommercial distribution and only if you
received the program in object code or executable form with such
an offer, in accord with Subsection b above.)
The source code for a work means the preferred form of the work for
making modifications to it. For an executable work, complete source
code means all the source code for all modules it contains, plus any
associated interface definition files, plus the scripts used to
control compilation and installation of the executable. However, as a
special exception, the source code distributed need not include
anything that is normally distributed (in either source or binary
form) with the major components (compiler, kernel, and so on) of the
operating system on which the executable runs, unless that component
itself accompanies the executable.
If distribution of executable or object code is made by offering
access to copy from a designated place, then offering equivalent
access to copy the source code from the same place counts as
distribution of the source code, even though third parties are not
compelled to copy the source along with the object code.
4. You may not copy, modify, sublicense, or distribute the Program
except as expressly provided under this License. Any attempt
otherwise to copy, modify, sublicense or distribute the Program is
void, and will automatically terminate your rights under this License.
However, parties who have received copies, or rights, from you under
this License will not have their licenses terminated so long as such
parties remain in full compliance.
5. You are not required to accept this License, since you have not
signed it. However, nothing else grants you permission to modify or
distribute the Program or its derivative works. These actions are
prohibited by law if you do not accept this License. Therefore, by
modifying or distributing the Program (or any work based on the
Program), you indicate your acceptance of this License to do so, and
all its terms and conditions for copying, distributing or modifying
the Program or works based on it.
6. Each time you redistribute the Program (or any work based on the
Program), the recipient automatically receives a license from the
original licensor to copy, distribute or modify the Program subject to
these terms and conditions. You may not impose any further
restrictions on the recipients' exercise of the rights granted herein.
You are not responsible for enforcing compliance by third parties to
this License.
7. If, as a consequence of a court judgment or allegation of patent
infringement or for any other reason (not limited to patent issues),
conditions are imposed on you (whether by court order, agreement or
otherwise) that contradict the conditions of this License, they do not
excuse you from the conditions of this License. If you cannot
distribute so as to satisfy simultaneously your obligations under this
License and any other pertinent obligations, then as a consequence you
may not distribute the Program at all. For example, if a patent
license would not permit royalty-free redistribution of the Program by
all those who receive copies directly or indirectly through you, then
the only way you could satisfy both it and this License would be to
refrain entirely from distribution of the Program.
If any portion of this section is held invalid or unenforceable under
any particular circumstance, the balance of the section is intended to
apply and the section as a whole is intended to apply in other
circumstances.
It is not the purpose of this section to induce you to infringe any
patents or other property right claims or to contest validity of any
such claims; this section has the sole purpose of protecting the
integrity of the free software distribution system, which is
implemented by public license practices. Many people have made
generous contributions to the wide range of software distributed
through that system in reliance on consistent application of that
system; it is up to the author/donor to decide if he or she is willing
to distribute software through any other system and a licensee cannot
impose that choice.
This section is intended to make thoroughly clear what is believed to
be a consequence of the rest of this License.
8. If the distribution and/or use of the Program is restricted in
certain countries either by patents or by copyrighted interfaces, the
original copyright holder who places the Program under this License
may add an explicit geographical distribution limitation excluding
those countries, so that distribution is permitted only in or among
countries not thus excluded. In such case, this License incorporates
the limitation as if written in the body of this License.
9. The Free Software Foundation may publish revised and/or new versions
of the General Public License from time to time. Such new versions will
be similar in spirit to the present version, but may differ in detail to
address new problems or concerns.
Each version is given a distinguishing version number. If the Program
specifies a version number of this License which applies to it and "any
later version", you have the option of following the terms and conditions
either of that version or of any later version published by the Free
Software Foundation. If the Program does not specify a version number of
this License, you may choose any version ever published by the Free Software
Foundation.
10. If you wish to incorporate parts of the Program into other free
programs whose distribution conditions are different, write to the author
to ask for permission. For software which is copyrighted by the Free
Software Foundation, write to the Free Software Foundation; we sometimes
make exceptions for this. Our decision will be guided by the two goals
of preserving the free status of all derivatives of our free software and
of promoting the sharing and reuse of software generally.
NO WARRANTY
11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
REPAIR OR CORRECTION.
12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
POSSIBILITY OF SUCH DAMAGES.
END OF TERMS AND CONDITIONS
How to Apply These Terms to Your New Programs
If you develop a new program, and you want it to be of the greatest
possible use to the public, the best way to achieve this is to make it
free software which everyone can redistribute and change under these terms.
To do so, attach the following notices to the program. It is safest
to attach them to the start of each source file to most effectively
convey the exclusion of warranty; and each file should have at least
the "copyright" line and a pointer to where the full notice is found.
<one line to give the program's name and a brief idea of what it does.>
Copyright (C) 19yy <name of author>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
Also add information on how to contact you by electronic and paper mail.
If the program is interactive, make it output a short notice like this
when it starts in an interactive mode:
Gnomovision version 69, Copyright (C) 19yy name of author
Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
This is free software, and you are welcome to redistribute it
under certain conditions; type `show c' for details.
The hypothetical commands `show w' and `show c' should show the appropriate
parts of the General Public License. Of course, the commands you use may
be called something other than `show w' and `show c'; they could even be
mouse-clicks or menu items--whatever suits your program.
You should also get your employer (if you work as a programmer) or your
school, if any, to sign a "copyright disclaimer" for the program, if
necessary. Here is a sample; alter the names:
Yoyodyne, Inc., hereby disclaims all copyright interest in the program
`Gnomovision' (which makes passes at compilers) written by James Hacker.
<signature of Ty Coon>, 1 April 1989
Ty Coon, President of Vice
This General Public License does not permit incorporating your program into
proprietary programs. If your program is a subroutine library, you may
consider it more useful to permit linking proprietary applications with the
library. If this is what you want to do, use the GNU Library General
Public License instead of this License.

397
libkcddb/COPYING.DOC Normal file
View file

@ -0,0 +1,397 @@
GNU Free Documentation License
Version 1.2, November 2002
Copyright (C) 2000,2001,2002 Free Software Foundation, Inc.
51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
0. PREAMBLE
The purpose of this License is to make a manual, textbook, or other
functional and useful document "free" in the sense of freedom: to
assure everyone the effective freedom to copy and redistribute it,
with or without modifying it, either commercially or noncommercially.
Secondarily, this License preserves for the author and publisher a way
to get credit for their work, while not being considered responsible
for modifications made by others.
This License is a kind of "copyleft", which means that derivative
works of the document must themselves be free in the same sense. It
complements the GNU General Public License, which is a copyleft
license designed for free software.
We have designed this License in order to use it for manuals for free
software, because free software needs free documentation: a free
program should come with manuals providing the same freedoms that the
software does. But this License is not limited to software manuals;
it can be used for any textual work, regardless of subject matter or
whether it is published as a printed book. We recommend this License
principally for works whose purpose is instruction or reference.
1. APPLICABILITY AND DEFINITIONS
This License applies to any manual or other work, in any medium, that
contains a notice placed by the copyright holder saying it can be
distributed under the terms of this License. Such a notice grants a
world-wide, royalty-free license, unlimited in duration, to use that
work under the conditions stated herein. The "Document", below,
refers to any such manual or work. Any member of the public is a
licensee, and is addressed as "you". You accept the license if you
copy, modify or distribute the work in a way requiring permission
under copyright law.
A "Modified Version" of the Document means any work containing the
Document or a portion of it, either copied verbatim, or with
modifications and/or translated into another language.
A "Secondary Section" is a named appendix or a front-matter section of
the Document that deals exclusively with the relationship of the
publishers or authors of the Document to the Document's overall subject
(or to related matters) and contains nothing that could fall directly
within that overall subject. (Thus, if the Document is in part a
textbook of mathematics, a Secondary Section may not explain any
mathematics.) The relationship could be a matter of historical
connection with the subject or with related matters, or of legal,
commercial, philosophical, ethical or political position regarding
them.
The "Invariant Sections" are certain Secondary Sections whose titles
are designated, as being those of Invariant Sections, in the notice
that says that the Document is released under this License. If a
section does not fit the above definition of Secondary then it is not
allowed to be designated as Invariant. The Document may contain zero
Invariant Sections. If the Document does not identify any Invariant
Sections then there are none.
The "Cover Texts" are certain short passages of text that are listed,
as Front-Cover Texts or Back-Cover Texts, in the notice that says that
the Document is released under this License. A Front-Cover Text may
be at most 5 words, and a Back-Cover Text may be at most 25 words.
A "Transparent" copy of the Document means a machine-readable copy,
represented in a format whose specification is available to the
general public, that is suitable for revising the document
straightforwardly with generic text editors or (for images composed of
pixels) generic paint programs or (for drawings) some widely available
drawing editor, and that is suitable for input to text formatters or
for automatic translation to a variety of formats suitable for input
to text formatters. A copy made in an otherwise Transparent file
format whose markup, or absence of markup, has been arranged to thwart
or discourage subsequent modification by readers is not Transparent.
An image format is not Transparent if used for any substantial amount
of text. A copy that is not "Transparent" is called "Opaque".
Examples of suitable formats for Transparent copies include plain
ASCII without markup, Texinfo input format, LaTeX input format, SGML
or XML using a publicly available DTD, and standard-conforming simple
HTML, PostScript or PDF designed for human modification. Examples of
transparent image formats include PNG, XCF and JPG. Opaque formats
include proprietary formats that can be read and edited only by
proprietary word processors, SGML or XML for which the DTD and/or
processing tools are not generally available, and the
machine-generated HTML, PostScript or PDF produced by some word
processors for output purposes only.
The "Title Page" means, for a printed book, the title page itself,
plus such following pages as are needed to hold, legibly, the material
this License requires to appear in the title page. For works in
formats which do not have any title page as such, "Title Page" means
the text near the most prominent appearance of the work's title,
preceding the beginning of the body of the text.
A section "Entitled XYZ" means a named subunit of the Document whose
title either is precisely XYZ or contains XYZ in parentheses following
text that translates XYZ in another language. (Here XYZ stands for a
specific section name mentioned below, such as "Acknowledgements",
"Dedications", "Endorsements", or "History".) To "Preserve the Title"
of such a section when you modify the Document means that it remains a
section "Entitled XYZ" according to this definition.
The Document may include Warranty Disclaimers next to the notice which
states that this License applies to the Document. These Warranty
Disclaimers are considered to be included by reference in this
License, but only as regards disclaiming warranties: any other
implication that these Warranty Disclaimers may have is void and has
no effect on the meaning of this License.
2. VERBATIM COPYING
You may copy and distribute the Document in any medium, either
commercially or noncommercially, provided that this License, the
copyright notices, and the license notice saying this License applies
to the Document are reproduced in all copies, and that you add no other
conditions whatsoever to those of this License. You may not use
technical measures to obstruct or control the reading or further
copying of the copies you make or distribute. However, you may accept
compensation in exchange for copies. If you distribute a large enough
number of copies you must also follow the conditions in section 3.
You may also lend copies, under the same conditions stated above, and
you may publicly display copies.
3. COPYING IN QUANTITY
If you publish printed copies (or copies in media that commonly have
printed covers) of the Document, numbering more than 100, and the
Document's license notice requires Cover Texts, you must enclose the
copies in covers that carry, clearly and legibly, all these Cover
Texts: Front-Cover Texts on the front cover, and Back-Cover Texts on
the back cover. Both covers must also clearly and legibly identify
you as the publisher of these copies. The front cover must present
the full title with all words of the title equally prominent and
visible. You may add other material on the covers in addition.
Copying with changes limited to the covers, as long as they preserve
the title of the Document and satisfy these conditions, can be treated
as verbatim copying in other respects.
If the required texts for either cover are too voluminous to fit
legibly, you should put the first ones listed (as many as fit
reasonably) on the actual cover, and continue the rest onto adjacent
pages.
If you publish or distribute Opaque copies of the Document numbering
more than 100, you must either include a machine-readable Transparent
copy along with each Opaque copy, or state in or with each Opaque copy
a computer-network location from which the general network-using
public has access to download using public-standard network protocols
a complete Transparent copy of the Document, free of added material.
If you use the latter option, you must take reasonably prudent steps,
when you begin distribution of Opaque copies in quantity, to ensure
that this Transparent copy will remain thus accessible at the stated
location until at least one year after the last time you distribute an
Opaque copy (directly or through your agents or retailers) of that
edition to the public.
It is requested, but not required, that you contact the authors of the
Document well before redistributing any large number of copies, to give
them a chance to provide you with an updated version of the Document.
4. MODIFICATIONS
You may copy and distribute a Modified Version of the Document under
the conditions of sections 2 and 3 above, provided that you release
the Modified Version under precisely this License, with the Modified
Version filling the role of the Document, thus licensing distribution
and modification of the Modified Version to whoever possesses a copy
of it. In addition, you must do these things in the Modified Version:
A. Use in the Title Page (and on the covers, if any) a title distinct
from that of the Document, and from those of previous versions
(which should, if there were any, be listed in the History section
of the Document). You may use the same title as a previous version
if the original publisher of that version gives permission.
B. List on the Title Page, as authors, one or more persons or entities
responsible for authorship of the modifications in the Modified
Version, together with at least five of the principal authors of the
Document (all of its principal authors, if it has fewer than five),
unless they release you from this requirement.
C. State on the Title page the name of the publisher of the
Modified Version, as the publisher.
D. Preserve all the copyright notices of the Document.
E. Add an appropriate copyright notice for your modifications
adjacent to the other copyright notices.
F. Include, immediately after the copyright notices, a license notice
giving the public permission to use the Modified Version under the
terms of this License, in the form shown in the Addendum below.
G. Preserve in that license notice the full lists of Invariant Sections
and required Cover Texts given in the Document's license notice.
H. Include an unaltered copy of this License.
I. Preserve the section Entitled "History", Preserve its Title, and add
to it an item stating at least the title, year, new authors, and
publisher of the Modified Version as given on the Title Page. If
there is no section Entitled "History" in the Document, create one
stating the title, year, authors, and publisher of the Document as
given on its Title Page, then add an item describing the Modified
Version as stated in the previous sentence.
J. Preserve the network location, if any, given in the Document for
public access to a Transparent copy of the Document, and likewise
the network locations given in the Document for previous versions
it was based on. These may be placed in the "History" section.
You may omit a network location for a work that was published at
least four years before the Document itself, or if the original
publisher of the version it refers to gives permission.
K. For any section Entitled "Acknowledgements" or "Dedications",
Preserve the Title of the section, and preserve in the section all
the substance and tone of each of the contributor acknowledgements
and/or dedications given therein.
L. Preserve all the Invariant Sections of the Document,
unaltered in their text and in their titles. Section numbers
or the equivalent are not considered part of the section titles.
M. Delete any section Entitled "Endorsements". Such a section
may not be included in the Modified Version.
N. Do not retitle any existing section to be Entitled "Endorsements"
or to conflict in title with any Invariant Section.
O. Preserve any Warranty Disclaimers.
If the Modified Version includes new front-matter sections or
appendices that qualify as Secondary Sections and contain no material
copied from the Document, you may at your option designate some or all
of these sections as invariant. To do this, add their titles to the
list of Invariant Sections in the Modified Version's license notice.
These titles must be distinct from any other section titles.
You may add a section Entitled "Endorsements", provided it contains
nothing but endorsements of your Modified Version by various
parties--for example, statements of peer review or that the text has
been approved by an organization as the authoritative definition of a
standard.
You may add a passage of up to five words as a Front-Cover Text, and a
passage of up to 25 words as a Back-Cover Text, to the end of the list
of Cover Texts in the Modified Version. Only one passage of
Front-Cover Text and one of Back-Cover Text may be added by (or
through arrangements made by) any one entity. If the Document already
includes a cover text for the same cover, previously added by you or
by arrangement made by the same entity you are acting on behalf of,
you may not add another; but you may replace the old one, on explicit
permission from the previous publisher that added the old one.
The author(s) and publisher(s) of the Document do not by this License
give permission to use their names for publicity for or to assert or
imply endorsement of any Modified Version.
5. COMBINING DOCUMENTS
You may combine the Document with other documents released under this
License, under the terms defined in section 4 above for modified
versions, provided that you include in the combination all of the
Invariant Sections of all of the original documents, unmodified, and
list them all as Invariant Sections of your combined work in its
license notice, and that you preserve all their Warranty Disclaimers.
The combined work need only contain one copy of this License, and
multiple identical Invariant Sections may be replaced with a single
copy. If there are multiple Invariant Sections with the same name but
different contents, make the title of each such section unique by
adding at the end of it, in parentheses, the name of the original
author or publisher of that section if known, or else a unique number.
Make the same adjustment to the section titles in the list of
Invariant Sections in the license notice of the combined work.
In the combination, you must combine any sections Entitled "History"
in the various original documents, forming one section Entitled
"History"; likewise combine any sections Entitled "Acknowledgements",
and any sections Entitled "Dedications". You must delete all sections
Entitled "Endorsements".
6. COLLECTIONS OF DOCUMENTS
You may make a collection consisting of the Document and other documents
released under this License, and replace the individual copies of this
License in the various documents with a single copy that is included in
the collection, provided that you follow the rules of this License for
verbatim copying of each of the documents in all other respects.
You may extract a single document from such a collection, and distribute
it individually under this License, provided you insert a copy of this
License into the extracted document, and follow this License in all
other respects regarding verbatim copying of that document.
7. AGGREGATION WITH INDEPENDENT WORKS
A compilation of the Document or its derivatives with other separate
and independent documents or works, in or on a volume of a storage or
distribution medium, is called an "aggregate" if the copyright
resulting from the compilation is not used to limit the legal rights
of the compilation's users beyond what the individual works permit.
When the Document is included in an aggregate, this License does not
apply to the other works in the aggregate which are not themselves
derivative works of the Document.
If the Cover Text requirement of section 3 is applicable to these
copies of the Document, then if the Document is less than one half of
the entire aggregate, the Document's Cover Texts may be placed on
covers that bracket the Document within the aggregate, or the
electronic equivalent of covers if the Document is in electronic form.
Otherwise they must appear on printed covers that bracket the whole
aggregate.
8. TRANSLATION
Translation is considered a kind of modification, so you may
distribute translations of the Document under the terms of section 4.
Replacing Invariant Sections with translations requires special
permission from their copyright holders, but you may include
translations of some or all Invariant Sections in addition to the
original versions of these Invariant Sections. You may include a
translation of this License, and all the license notices in the
Document, and any Warranty Disclaimers, provided that you also include
the original English version of this License and the original versions
of those notices and disclaimers. In case of a disagreement between
the translation and the original version of this License or a notice
or disclaimer, the original version will prevail.
If a section in the Document is Entitled "Acknowledgements",
"Dedications", or "History", the requirement (section 4) to Preserve
its Title (section 1) will typically require changing the actual
title.
9. TERMINATION
You may not copy, modify, sublicense, or distribute the Document except
as expressly provided for under this License. Any other attempt to
copy, modify, sublicense or distribute the Document is void, and will
automatically terminate your rights under this License. However,
parties who have received copies, or rights, from you under this
License will not have their licenses terminated so long as such
parties remain in full compliance.
10. FUTURE REVISIONS OF THIS LICENSE
The Free Software Foundation may publish new, revised versions
of the GNU Free Documentation License from time to time. Such new
versions will be similar in spirit to the present version, but may
differ in detail to address new problems or concerns. See
http://www.gnu.org/copyleft/.
Each version of the License is given a distinguishing version number.
If the Document specifies that a particular numbered version of this
License "or any later version" applies to it, you have the option of
following the terms and conditions either of that specified version or
of any later version that has been published (not as a draft) by the
Free Software Foundation. If the Document does not specify a version
number of this License, you may choose any version ever published (not
as a draft) by the Free Software Foundation.
ADDENDUM: How to use this License for your documents
To use this License in a document you have written, include a copy of
the License in the document and put the following copyright and
license notices just after the title page:
Copyright (c) YEAR YOUR NAME.
Permission is granted to copy, distribute and/or modify this document
under the terms of the GNU Free Documentation License, Version 1.2
or any later version published by the Free Software Foundation;
with no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts.
A copy of the license is included in the section entitled "GNU
Free Documentation License".
If you have Invariant Sections, Front-Cover Texts and Back-Cover Texts,
replace the "with...Texts." line with this:
with the Invariant Sections being LIST THEIR TITLES, with the
Front-Cover Texts being LIST, and with the Back-Cover Texts being LIST.
If you have Invariant Sections without Cover Texts, or some other
combination of the three, merge those two alternatives to suit the
situation.
If your document contains nontrivial examples of program code, we
recommend releasing these examples in parallel under your choice of
free software license, such as the GNU General Public License,
to permit their use in free software.

481
libkcddb/COPYING.LIB Normal file
View file

@ -0,0 +1,481 @@
GNU LIBRARY GENERAL PUBLIC LICENSE
Version 2, June 1991
Copyright (C) 1991 Free Software Foundation, Inc.
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
[This is the first released version of the library GPL. It is
numbered 2 because it goes with version 2 of the ordinary GPL.]
Preamble
The licenses for most software are designed to take away your
freedom to share and change it. By contrast, the GNU General Public
Licenses are intended to guarantee your freedom to share and change
free software--to make sure the software is free for all its users.
This license, the Library General Public License, applies to some
specially designated Free Software Foundation software, and to any
other libraries whose authors decide to use it. You can use it for
your libraries, too.
When we speak of free software, we are referring to freedom, not
price. Our General Public Licenses are designed to make sure that you
have the freedom to distribute copies of free software (and charge for
this service if you wish), that you receive source code or can get it
if you want it, that you can change the software or use pieces of it
in new free programs; and that you know you can do these things.
To protect your rights, we need to make restrictions that forbid
anyone to deny you these rights or to ask you to surrender the rights.
These restrictions translate to certain responsibilities for you if
you distribute copies of the library, or if you modify it.
For example, if you distribute copies of the library, whether gratis
or for a fee, you must give the recipients all the rights that we gave
you. You must make sure that they, too, receive or can get the source
code. If you link a program with the library, you must provide
complete object files to the recipients so that they can relink them
with the library, after making changes to the library and recompiling
it. And you must show them these terms so they know their rights.
Our method of protecting your rights has two steps: (1) copyright
the library, and (2) offer you this license which gives you legal
permission to copy, distribute and/or modify the library.
Also, for each distributor's protection, we want to make certain
that everyone understands that there is no warranty for this free
library. If the library is modified by someone else and passed on, we
want its recipients to know that what they have is not the original
version, so that any problems introduced by others will not reflect on
the original authors' reputations.
Finally, any free program is threatened constantly by software
patents. We wish to avoid the danger that companies distributing free
software will individually obtain patent licenses, thus in effect
transforming the program into proprietary software. To prevent this,
we have made it clear that any patent must be licensed for everyone's
free use or not licensed at all.
Most GNU software, including some libraries, is covered by the ordinary
GNU General Public License, which was designed for utility programs. This
license, the GNU Library General Public License, applies to certain
designated libraries. This license is quite different from the ordinary
one; be sure to read it in full, and don't assume that anything in it is
the same as in the ordinary license.
The reason we have a separate public license for some libraries is that
they blur the distinction we usually make between modifying or adding to a
program and simply using it. Linking a program with a library, without
changing the library, is in some sense simply using the library, and is
analogous to running a utility program or application program. However, in
a textual and legal sense, the linked executable is a combined work, a
derivative of the original library, and the ordinary General Public License
treats it as such.
Because of this blurred distinction, using the ordinary General
Public License for libraries did not effectively promote software
sharing, because most developers did not use the libraries. We
concluded that weaker conditions might promote sharing better.
However, unrestricted linking of non-free programs would deprive the
users of those programs of all benefit from the free status of the
libraries themselves. This Library General Public License is intended to
permit developers of non-free programs to use free libraries, while
preserving your freedom as a user of such programs to change the free
libraries that are incorporated in them. (We have not seen how to achieve
this as regards changes in header files, but we have achieved it as regards
changes in the actual functions of the Library.) The hope is that this
will lead to faster development of free libraries.
The precise terms and conditions for copying, distribution and
modification follow. Pay close attention to the difference between a
"work based on the library" and a "work that uses the library". The
former contains code derived from the library, while the latter only
works together with the library.
Note that it is possible for a library to be covered by the ordinary
General Public License rather than by this special one.
GNU LIBRARY GENERAL PUBLIC LICENSE
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
0. This License Agreement applies to any software library which
contains a notice placed by the copyright holder or other authorized
party saying it may be distributed under the terms of this Library
General Public License (also called "this License"). Each licensee is
addressed as "you".
A "library" means a collection of software functions and/or data
prepared so as to be conveniently linked with application programs
(which use some of those functions and data) to form executables.
The "Library", below, refers to any such software library or work
which has been distributed under these terms. A "work based on the
Library" means either the Library or any derivative work under
copyright law: that is to say, a work containing the Library or a
portion of it, either verbatim or with modifications and/or translated
straightforwardly into another language. (Hereinafter, translation is
included without limitation in the term "modification".)
"Source code" for a work means the preferred form of the work for
making modifications to it. For a library, complete source code means
all the source code for all modules it contains, plus any associated
interface definition files, plus the scripts used to control compilation
and installation of the library.
Activities other than copying, distribution and modification are not
covered by this License; they are outside its scope. The act of
running a program using the Library is not restricted, and output from
such a program is covered only if its contents constitute a work based
on the Library (independent of the use of the Library in a tool for
writing it). Whether that is true depends on what the Library does
and what the program that uses the Library does.
1. You may copy and distribute verbatim copies of the Library's
complete source code as you receive it, in any medium, provided that
you conspicuously and appropriately publish on each copy an
appropriate copyright notice and disclaimer of warranty; keep intact
all the notices that refer to this License and to the absence of any
warranty; and distribute a copy of this License along with the
Library.
You may charge a fee for the physical act of transferring a copy,
and you may at your option offer warranty protection in exchange for a
fee.
2. You may modify your copy or copies of the Library or any portion
of it, thus forming a work based on the Library, and copy and
distribute such modifications or work under the terms of Section 1
above, provided that you also meet all of these conditions:
a) The modified work must itself be a software library.
b) You must cause the files modified to carry prominent notices
stating that you changed the files and the date of any change.
c) You must cause the whole of the work to be licensed at no
charge to all third parties under the terms of this License.
d) If a facility in the modified Library refers to a function or a
table of data to be supplied by an application program that uses
the facility, other than as an argument passed when the facility
is invoked, then you must make a good faith effort to ensure that,
in the event an application does not supply such function or
table, the facility still operates, and performs whatever part of
its purpose remains meaningful.
(For example, a function in a library to compute square roots has
a purpose that is entirely well-defined independent of the
application. Therefore, Subsection 2d requires that any
application-supplied function or table used by this function must
be optional: if the application does not supply it, the square
root function must still compute square roots.)
These requirements apply to the modified work as a whole. If
identifiable sections of that work are not derived from the Library,
and can be reasonably considered independent and separate works in
themselves, then this License, and its terms, do not apply to those
sections when you distribute them as separate works. But when you
distribute the same sections as part of a whole which is a work based
on the Library, the distribution of the whole must be on the terms of
this License, whose permissions for other licensees extend to the
entire whole, and thus to each and every part regardless of who wrote
it.
Thus, it is not the intent of this section to claim rights or contest
your rights to work written entirely by you; rather, the intent is to
exercise the right to control the distribution of derivative or
collective works based on the Library.
In addition, mere aggregation of another work not based on the Library
with the Library (or with a work based on the Library) on a volume of
a storage or distribution medium does not bring the other work under
the scope of this License.
3. You may opt to apply the terms of the ordinary GNU General Public
License instead of this License to a given copy of the Library. To do
this, you must alter all the notices that refer to this License, so
that they refer to the ordinary GNU General Public License, version 2,
instead of to this License. (If a newer version than version 2 of the
ordinary GNU General Public License has appeared, then you can specify
that version instead if you wish.) Do not make any other change in
these notices.
Once this change is made in a given copy, it is irreversible for
that copy, so the ordinary GNU General Public License applies to all
subsequent copies and derivative works made from that copy.
This option is useful when you wish to copy part of the code of
the Library into a program that is not a library.
4. You may copy and distribute the Library (or a portion or
derivative of it, under Section 2) in object code or executable form
under the terms of Sections 1 and 2 above provided that you accompany
it with the complete corresponding machine-readable source code, which
must be distributed under the terms of Sections 1 and 2 above on a
medium customarily used for software interchange.
If distribution of object code is made by offering access to copy
from a designated place, then offering equivalent access to copy the
source code from the same place satisfies the requirement to
distribute the source code, even though third parties are not
compelled to copy the source along with the object code.
5. A program that contains no derivative of any portion of the
Library, but is designed to work with the Library by being compiled or
linked with it, is called a "work that uses the Library". Such a
work, in isolation, is not a derivative work of the Library, and
therefore falls outside the scope of this License.
However, linking a "work that uses the Library" with the Library
creates an executable that is a derivative of the Library (because it
contains portions of the Library), rather than a "work that uses the
library". The executable is therefore covered by this License.
Section 6 states terms for distribution of such executables.
When a "work that uses the Library" uses material from a header file
that is part of the Library, the object code for the work may be a
derivative work of the Library even though the source code is not.
Whether this is true is especially significant if the work can be
linked without the Library, or if the work is itself a library. The
threshold for this to be true is not precisely defined by law.
If such an object file uses only numerical parameters, data
structure layouts and accessors, and small macros and small inline
functions (ten lines or less in length), then the use of the object
file is unrestricted, regardless of whether it is legally a derivative
work. (Executables containing this object code plus portions of the
Library will still fall under Section 6.)
Otherwise, if the work is a derivative of the Library, you may
distribute the object code for the work under the terms of Section 6.
Any executables containing that work also fall under Section 6,
whether or not they are linked directly with the Library itself.
6. As an exception to the Sections above, you may also compile or
link a "work that uses the Library" with the Library to produce a
work containing portions of the Library, and distribute that work
under terms of your choice, provided that the terms permit
modification of the work for the customer's own use and reverse
engineering for debugging such modifications.
You must give prominent notice with each copy of the work that the
Library is used in it and that the Library and its use are covered by
this License. You must supply a copy of this License. If the work
during execution displays copyright notices, you must include the
copyright notice for the Library among them, as well as a reference
directing the user to the copy of this License. Also, you must do one
of these things:
a) Accompany the work with the complete corresponding
machine-readable source code for the Library including whatever
changes were used in the work (which must be distributed under
Sections 1 and 2 above); and, if the work is an executable linked
with the Library, with the complete machine-readable "work that
uses the Library", as object code and/or source code, so that the
user can modify the Library and then relink to produce a modified
executable containing the modified Library. (It is understood
that the user who changes the contents of definitions files in the
Library will not necessarily be able to recompile the application
to use the modified definitions.)
b) Accompany the work with a written offer, valid for at
least three years, to give the same user the materials
specified in Subsection 6a, above, for a charge no more
than the cost of performing this distribution.
c) If distribution of the work is made by offering access to copy
from a designated place, offer equivalent access to copy the above
specified materials from the same place.
d) Verify that the user has already received a copy of these
materials or that you have already sent this user a copy.
For an executable, the required form of the "work that uses the
Library" must include any data and utility programs needed for
reproducing the executable from it. However, as a special exception,
the source code distributed need not include anything that is normally
distributed (in either source or binary form) with the major
components (compiler, kernel, and so on) of the operating system on
which the executable runs, unless that component itself accompanies
the executable.
It may happen that this requirement contradicts the license
restrictions of other proprietary libraries that do not normally
accompany the operating system. Such a contradiction means you cannot
use both them and the Library together in an executable that you
distribute.
7. You may place library facilities that are a work based on the
Library side-by-side in a single library together with other library
facilities not covered by this License, and distribute such a combined
library, provided that the separate distribution of the work based on
the Library and of the other library facilities is otherwise
permitted, and provided that you do these two things:
a) Accompany the combined library with a copy of the same work
based on the Library, uncombined with any other library
facilities. This must be distributed under the terms of the
Sections above.
b) Give prominent notice with the combined library of the fact
that part of it is a work based on the Library, and explaining
where to find the accompanying uncombined form of the same work.
8. You may not copy, modify, sublicense, link with, or distribute
the Library except as expressly provided under this License. Any
attempt otherwise to copy, modify, sublicense, link with, or
distribute the Library is void, and will automatically terminate your
rights under this License. However, parties who have received copies,
or rights, from you under this License will not have their licenses
terminated so long as such parties remain in full compliance.
9. You are not required to accept this License, since you have not
signed it. However, nothing else grants you permission to modify or
distribute the Library or its derivative works. These actions are
prohibited by law if you do not accept this License. Therefore, by
modifying or distributing the Library (or any work based on the
Library), you indicate your acceptance of this License to do so, and
all its terms and conditions for copying, distributing or modifying
the Library or works based on it.
10. Each time you redistribute the Library (or any work based on the
Library), the recipient automatically receives a license from the
original licensor to copy, distribute, link with or modify the Library
subject to these terms and conditions. You may not impose any further
restrictions on the recipients' exercise of the rights granted herein.
You are not responsible for enforcing compliance by third parties to
this License.
11. If, as a consequence of a court judgment or allegation of patent
infringement or for any other reason (not limited to patent issues),
conditions are imposed on you (whether by court order, agreement or
otherwise) that contradict the conditions of this License, they do not
excuse you from the conditions of this License. If you cannot
distribute so as to satisfy simultaneously your obligations under this
License and any other pertinent obligations, then as a consequence you
may not distribute the Library at all. For example, if a patent
license would not permit royalty-free redistribution of the Library by
all those who receive copies directly or indirectly through you, then
the only way you could satisfy both it and this License would be to
refrain entirely from distribution of the Library.
If any portion of this section is held invalid or unenforceable under any
particular circumstance, the balance of the section is intended to apply,
and the section as a whole is intended to apply in other circumstances.
It is not the purpose of this section to induce you to infringe any
patents or other property right claims or to contest validity of any
such claims; this section has the sole purpose of protecting the
integrity of the free software distribution system which is
implemented by public license practices. Many people have made
generous contributions to the wide range of software distributed
through that system in reliance on consistent application of that
system; it is up to the author/donor to decide if he or she is willing
to distribute software through any other system and a licensee cannot
impose that choice.
This section is intended to make thoroughly clear what is believed to
be a consequence of the rest of this License.
12. If the distribution and/or use of the Library is restricted in
certain countries either by patents or by copyrighted interfaces, the
original copyright holder who places the Library under this License may add
an explicit geographical distribution limitation excluding those countries,
so that distribution is permitted only in or among countries not thus
excluded. In such case, this License incorporates the limitation as if
written in the body of this License.
13. The Free Software Foundation may publish revised and/or new
versions of the Library General Public License from time to time.
Such new versions will be similar in spirit to the present version,
but may differ in detail to address new problems or concerns.
Each version is given a distinguishing version number. If the Library
specifies a version number of this License which applies to it and
"any later version", you have the option of following the terms and
conditions either of that version or of any later version published by
the Free Software Foundation. If the Library does not specify a
license version number, you may choose any version ever published by
the Free Software Foundation.
14. If you wish to incorporate parts of the Library into other free
programs whose distribution conditions are incompatible with these,
write to the author to ask for permission. For software which is
copyrighted by the Free Software Foundation, write to the Free
Software Foundation; we sometimes make exceptions for this. Our
decision will be guided by the two goals of preserving the free status
of all derivatives of our free software and of promoting the sharing
and reuse of software generally.
NO WARRANTY
15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO
WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW.
EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR
OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY
KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE
LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME
THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN
WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY
AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU
FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR
CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE
LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING
RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A
FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF
SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
DAMAGES.
END OF TERMS AND CONDITIONS
How to Apply These Terms to Your New Libraries
If you develop a new library, and you want it to be of the greatest
possible use to the public, we recommend making it free software that
everyone can redistribute and change. You can do so by permitting
redistribution under these terms (or, alternatively, under the terms of the
ordinary General Public License).
To apply these terms, attach the following notices to the library. It is
safest to attach them to the start of each source file to most effectively
convey the exclusion of warranty; and each file should have at least the
"copyright" line and a pointer to where the full notice is found.
<one line to give the library's name and a brief idea of what it does.>
Copyright (C) <year> <name of author>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
Also add information on how to contact you by electronic and paper mail.
You should also get your employer (if you work as a programmer) or your
school, if any, to sign a "copyright disclaimer" for the library, if
necessary. Here is a sample; alter the names:
Yoyodyne, Inc., hereby disclaims all copyright interest in the
library `Frob' (a library for tweaking knobs) written by James Random Hacker.
<signature of Ty Coon>, 1 April 1990
Ty Coon, President of Vice
That's all there is to it!

5
libkcddb/Mainpage.dox Normal file
View file

@ -0,0 +1,5 @@
/**
* @mainpage KCDDB
*
**/
// DOXYGEN_EXCLUDE = kcmcddb musicbrainz tests

3
libkcddb/Messages.sh Normal file
View file

@ -0,0 +1,3 @@
#! /bin/sh
$EXTRACTRC `find . -name \*.ui -o -name \*.kcfg` >> rc.cpp
$XGETTEXT `find . -name \*.cpp` -o $podir/libkcddb.pot

12
libkcddb/TODO Normal file
View file

@ -0,0 +1,12 @@
Better error checking, for example checking if the config is empty
Try to comply with freedb's: "Guidelines for optimal freedb support"
http://www.freedb.org/modules.php?name=Sections&sop=viewarticle&artid=38
Saving playlist
Make it possible for a program to in some way mark that
an entry is not coming from freedb, but created from the
program. Now it's not possible to know the difference, so
the revision of a new entry is always 1 instead of 0 as
it should be

View file

@ -0,0 +1,2 @@
/* have MusicBrainz */
#cmakedefine HAVE_MUSICBRAINZ5 1

View file

@ -0,0 +1,22 @@
include_directories(
${CMAKE_CURRENT_SOURCE_DIR}/../libkcddb
${CMAKE_CURRENT_BINARY_DIR}/../libkcddb
)
########### next target ###############
set(kcm_cddb_PART_SRCS cddbconfigwidget.cpp kcmcddb.cpp cddbconfigwidget.ui)
kde4_add_plugin(kcm_cddb ${kcm_cddb_PART_SRCS})
target_link_libraries(kcm_cddb ${KDE4_KIO_LIBS} kcddb)
install(TARGETS kcm_cddb DESTINATION ${PLUGIN_INSTALL_DIR} )
########### install files ###############
install( FILES libkcddb.desktop DESTINATION ${SERVICES_INSTALL_DIR} )

View file

@ -0,0 +1,3 @@
#! /bin/sh
$EXTRACTRC *.ui >> rc.cpp
$XGETTEXT *.cpp -o $podir/kcmcddb.pot

View file

@ -0,0 +1,127 @@
/*
Copyright (C) 2002 Rik Hemsley (rikkus) <rik@kde.org>
Copyright (C) 2002 Benjamin Meyer <ben-devel@meyerhome.net>
Copyright (C) 2004 Richard Lärkäng <nouseforaname@home.se>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include "cddbconfigwidget.h"
#include "config-musicbrainz.h"
#include <kdemacros.h> // KDE_NO_DEPRECATED
#include "libkcddb/sites.h"
#include "libkcddb/lookup.h"
#include <qlist.h>
#include <kfiledialog.h>
#include <kapplication.h>
#include <klocale.h>
#include <kinputdialog.h>
#include <kmessagebox.h>
#include <keditlistwidget.h>
#include <kurlrequester.h>
#include <QCheckBox>
CDDBConfigWidget::CDDBConfigWidget(QWidget * parent)
: QWidget(parent)
{
setupUi(this);
#ifndef HAVE_MUSICBRAINZ5
kcfg_MusicBrainzLookupEnabled->hide();
#endif
// Connections from widgets are made in designer.
KUrlRequester* urlReq = new KUrlRequester(this);
urlReq->setMode(KFile::Directory);
QGroupBox* groupBox = new QGroupBox(cacheLocationsParent);
groupBox->setTitle(i18n("Cache Locations"));
QVBoxLayout* gbLayout = new QVBoxLayout(groupBox);
gbLayout->setMargin(0);
KEditListWidget* editListWidget = new KEditListWidget(groupBox);
editListWidget->setCustomEditor(urlReq->customEditor());
editListWidget->setObjectName(QString::fromLatin1("kcfg_cacheLocations"));
gbLayout->addWidget(editListWidget);
QHBoxLayout *layout = new QHBoxLayout(cacheLocationsParent);
layout->setMargin(0);
layout->addWidget(groupBox);
connect(needsAuthenticationBox,SIGNAL(toggled(bool)),SLOT(needAuthenticationChanged(bool)));
connect(kcfg_FreedbLookupTransport,SIGNAL(activated(int)),SLOT(protocolChanged()));
connect(kcfg_FreedbLookupEnabled,SIGNAL(toggled(bool)),freedbServerBox,SLOT(setEnabled(bool)));
connect(mirrorListButton,SIGNAL(clicked()),SLOT(showMirrorList()));
}
void CDDBConfigWidget::showMirrorList()
{
KCDDB::Sites s;
const QList<KCDDB::Mirror> sites = s.siteList();
QMap<QString, KCDDB::Mirror> keys;
for (QList<KCDDB::Mirror>::ConstIterator it = sites.begin(); it != sites.end(); ++it)
if ((*it).transport == KCDDB::Lookup::CDDBP)
keys[(*it).address + QLatin1String( "(CDDBP, " ) + QString::number((*it).port) + QLatin1String( ") " ) + (*it).description] = *it;
else
keys[(*it).address + QLatin1String( "(HTTP, " ) + QString::number((*it).port) + QLatin1String( ") " ) + (*it).description] = *it;
bool ok;
if (keys.isEmpty())
{
KMessageBox::information(this, i18n("Could not fetch mirror list."), i18n("Could Not Fetch"));
return;
}
QStringList result = KInputDialog::getItemList(i18n("Select mirror"),
i18n("Select one of these mirrors"), keys.keys(),
QStringList(), false, &ok, this);
if (ok && result.count() == 1)
{
KCDDB::Mirror m = keys[*(result.begin())];
kcfg_FreedbLookupTransport->setCurrentIndex(m.transport == KCDDB::Lookup::CDDBP ? 0 : 1);
kcfg_hostname->setText(m.address);
kcfg_port->setValue(m.port);
}
}
void CDDBConfigWidget::protocolChanged()
{
// Change the port if the port is the default-value for the old protocol
if (kcfg_FreedbLookupTransport->currentText() == i18n("HTTP") && kcfg_port->value() == 8880)
kcfg_port->setValue(80);
else if (kcfg_FreedbLookupTransport->currentText() == i18n("CDDB") && kcfg_port->value() == 80)
kcfg_port->setValue(8880);
}
void CDDBConfigWidget::needAuthenticationChanged(bool needsAuth)
{
kcfg_smtpUsername->setEnabled(needsAuth);
if (!needsAuth)
kcfg_smtpUsername->clear();
}
// vim:tabstop=2:shiftwidth=2:expandtab:cinoptions=(s,U1,m1
#include "moc_cddbconfigwidget.cpp"

View file

@ -0,0 +1,43 @@
/*
Copyright (C) 2002 Rik Hemsley (rikkus) <rik@kde.org>
Copyright (C) 2002 Benjamin Meyer <ben-devel@meyerhome.net>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#ifndef CDDB_CONFIG_WIDGET_H
#define CDDB_CONFIG_WIDGET_H
#include "ui_cddbconfigwidget.h"
class CDDBConfigWidget : public QWidget, public Ui::CDDBConfigWidgetBase
{
Q_OBJECT
public:
CDDBConfigWidget(QWidget * parent = 0);
protected slots:
virtual void showMirrorList();
virtual void protocolChanged();
virtual void needAuthenticationChanged(bool);
};
#endif // CDDB_CONFIG_WIDGET_H
// vim:tabstop=2:shiftwidth=2:expandtab:cinoptions=(s,U1,m1

View file

@ -0,0 +1,346 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<comment>Used for configuring libkcddb.</comment>
<class>CDDBConfigWidgetBase</class>
<widget class="QWidget" name="CDDBConfigWidgetBase">
<property name="windowTitle">
<string>CDDB Settings</string>
</property>
<layout class="QVBoxLayout">
<property name="margin">
<number>0</number>
</property>
<item>
<widget class="QTabWidget" name="tabWidget2">
<property name="currentIndex">
<number>0</number>
</property>
<widget class="QWidget" name="tabLookup">
<attribute name="title">
<string>&amp;Lookup</string>
</attribute>
<layout class="QVBoxLayout" name="gridLayout_4">
<item>
<widget class="QCheckBox" name="kcfg_MusicBrainzLookupEnabled">
<property name="text">
<string>Enable MusicBrainz lookup</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="kcfg_FreedbLookupEnabled">
<property name="text">
<string>Enable freedb lookup</string>
</property>
</widget>
</item>
<item>
<widget class="QGroupBox" name="freedbServerBox">
<property name="title">
<string>Freedb Server</string>
</property>
<layout class="QFormLayout" name="formLayout">
<item row="0" column="0">
<widget class="QLabel" name="TextLabel7">
<property name="text">
<string>Freedb server:</string>
</property>
<property name="buddy">
<cstring>kcfg_hostname</cstring>
</property>
</widget>
</item>
<item row="0" column="1">
<layout class="QHBoxLayout" name="horizontalLayout_6">
<item>
<widget class="QLineEdit" name="kcfg_hostname">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="whatsThis">
<string>Name of CDDB server which will be used to look up CD information.</string>
</property>
<property name="text">
<string>freedb.freedb.org</string>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="textLabel3_3">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Port:</string>
</property>
</widget>
</item>
<item>
<widget class="KIntSpinBox" name="kcfg_port">
<property name="sizePolicy">
<sizepolicy hsizetype="Maximum" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="whatsThis">
<string>Port to connect to on CDDB server.</string>
</property>
<property name="maximum">
<number>64000</number>
</property>
<property name="value">
<number>8880</number>
</property>
</widget>
</item>
</layout>
</item>
<item row="1" column="0">
<widget class="QLabel" name="TextLabel9">
<property name="text">
<string>&amp;Transport:</string>
</property>
<property name="buddy">
<cstring>kcfg_FreedbLookupTransport</cstring>
</property>
</widget>
</item>
<item row="1" column="1">
<layout class="QHBoxLayout" name="horizontalLayout_7">
<item>
<widget class="QComboBox" name="kcfg_FreedbLookupTransport">
<property name="whatsThis">
<string>Type of lookup which should be tried at the CDDB server.</string>
</property>
<item>
<property name="text">
<string>CDDB</string>
</property>
</item>
<item>
<property name="text">
<string>HTTP</string>
</property>
</item>
</widget>
</item>
<item>
<widget class="KPushButton" name="mirrorListButton">
<property name="text">
<string>Show &amp;Mirror List</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QWidget" name="cacheLocationsParent" native="true"/>
</item>
</layout>
</widget>
<widget class="QWidget" name="tabSubmit">
<attribute name="title">
<string>&amp;Submit</string>
</attribute>
<layout class="QVBoxLayout" name="gridLayout_2">
<item>
<layout class="QHBoxLayout" name="horizontalLayout_5">
<item>
<widget class="QLabel" name="textLabel1">
<property name="text">
<string>Email address:</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="kcfg_emailAddress"/>
</item>
</layout>
</item>
<item>
<widget class="QGroupBox" name="kcfg_FreedbSubmitTransport">
<property name="title">
<string>Submit Method</string>
</property>
<layout class="QFormLayout" name="formLayout_2">
<item row="0" column="0" colspan="2">
<widget class="QRadioButton" name="httpButton">
<property name="text">
<string>HTTP</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="textLabel2">
<property name="text">
<string>Server:</string>
</property>
</widget>
</item>
<item row="1" column="1">
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="KLineEdit" name="kcfg_httpSubmitServer">
</widget>
</item>
<item>
<widget class="QLabel" name="textLabel3_2">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Port:</string>
</property>
</widget>
</item>
<item>
<widget class="KIntSpinBox" name="kcfg_httpSubmitPort"/>
</item>
</layout>
</item>
<item row="2" column="0" colspan="2">
<widget class="QRadioButton" name="smtpButton">
<property name="text">
<string>SMTP (Email)</string>
</property>
</widget>
</item>
<item row="4" column="1">
<widget class="QLineEdit" name="kcfg_replyTo"/>
</item>
<item row="6" column="1">
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QLineEdit" name="kcfg_smtpHostname"/>
</item>
<item>
<widget class="QLabel" name="textLabel3">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Port:</string>
</property>
</widget>
</item>
<item>
<widget class="KIntSpinBox" name="kcfg_smtpPort">
<property name="sizePolicy">
<sizepolicy hsizetype="Maximum" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="maximum">
<number>65535</number>
</property>
<property name="value">
<number>25</number>
</property>
</widget>
</item>
</layout>
</item>
<item row="7" column="0" colspan="2">
<widget class="QCheckBox" name="needsAuthenticationBox">
<property name="text">
<string>Server needs authentication</string>
</property>
</widget>
</item>
<item row="9" column="1">
<widget class="QLineEdit" name="kcfg_smtpUsername">
<property name="enabled">
<bool>false</bool>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
<item row="4" column="0">
<widget class="QLabel" name="textLabel9_2">
<property name="text">
<string>Reply-To:</string>
</property>
</widget>
</item>
<item row="6" column="0">
<widget class="QLabel" name="textLabel2_2">
<property name="sizePolicy">
<sizepolicy hsizetype="Maximum" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>SMTP server:</string>
</property>
</widget>
</item>
<item row="9" column="0">
<widget class="QLabel" name="textLabel4">
<property name="text">
<string>Username:</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
</layout>
</widget>
</widget>
</item>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>KIntSpinBox</class>
<extends>QSpinBox</extends>
<header>knuminput.h</header>
<container>1</container>
</customwidget>
<customwidget>
<class>KLineEdit</class>
<extends>QLineEdit</extends>
<header>klineedit.h</header>
<container>1</container>
</customwidget>
<customwidget>
<class>KPushButton</class>
<extends>QPushButton</extends>
<header>kpushbutton.h</header>
<container>1</container>
</customwidget>
</customwidgets>
<tabstops>
<tabstop>kcfg_hostname</tabstop>
<tabstop>kcfg_port</tabstop>
<tabstop>kcfg_FreedbLookupTransport</tabstop>
</tabstops>
<resources/>
<connections/>
</ui>

View file

@ -0,0 +1,127 @@
/*
Copyright (C) 2002 Rik Hemsley (rikkus) <rik@kde.org>
Copyright (C) 2002 Benjamin Meyer <ben-devel@meyerhome.net>
Copyright (C) 2003 Richard Lärkäng <nouseforaname@home.se>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include "kcmcddb.h"
#include "cddbconfigwidget.h"
#include "libkcddb/lookup.h"
#include "libkcddb/cache.h"
#include "libkcddb/submit.h"
#include <QCheckBox>
#include <qradiobutton.h>
#include <QVBoxLayout>
#include <kconfig.h>
#include <klocale.h>
#include <kglobal.h>
#include <kpluginfactory.h>
#include <kmessagebox.h>
#include <kconfigdialogmanager.h>
K_PLUGIN_FACTORY(KCDDBFactory, registerPlugin<CDDBModule>();)
K_EXPORT_PLUGIN(KCDDBFactory( "kcmcddb" ))
CDDBModule::CDDBModule(QWidget *parent, const QVariantList &)
: KCModule(KCDDBFactory::componentData(), parent)
{
KGlobal::locale()->insertCatalog( QLatin1String( "libkcddb" ));
setButtons(Default | Apply | Help);
widget_ = new CDDBConfigWidget(this);
KCDDB::Config* cfg = new KCDDB::Config();
cfg->readConfig();
addConfig(cfg, widget_);
QVBoxLayout * layout = new QVBoxLayout(this);
layout->addWidget(widget_);
setQuickHelp(i18n("CDDB is used to get information like artist, title and song-names in CD's"));
load();
}
void
CDDBModule::defaults()
{
KCModule::defaults();
KCDDB::Config config;
updateWidgetsFromConfig( config );
}
void
CDDBModule::checkSettings() const
{
KCDDB::Config config;
config.readConfig();
if (config.smtpHostname().isEmpty() || config.emailAddress().isEmpty()
|| !config.emailAddress().contains(QLatin1String( "@" )) ||
(!config.replyTo().isEmpty() && !config.replyTo().contains(QLatin1String( "@" ))))
{
if (config.freedbSubmitTransport() == KCDDB::Submit::SMTP)
{
KMessageBox::sorry(widget_, i18n("freedb has been set to use HTTP for submissions "
"because the email details you have entered are "
"incomplete. Please review your email settings "
"and try again."), i18n("Incorrect Email Settings"));
config.setFreedbSubmitTransport(KCDDB::Submit::HTTP);
config.writeConfig();
}
}
}
void
CDDBModule::updateWidgetsFromConfig(const KCDDB::Config & config)
{
bool smtpUserIsEmpty = config.smtpUsername().isEmpty();
widget_->needsAuthenticationBox->setChecked(!smtpUserIsEmpty);
widget_->kcfg_smtpUsername->setEnabled(!smtpUserIsEmpty);
}
void
CDDBModule::save()
{
KCModule::save();
checkSettings();
}
void
CDDBModule::load()
{
KCModule::load();
KCDDB::Config config;
config.readConfig();
updateWidgetsFromConfig(config);
}
// vim:tabstop=2:shiftwidth=2:expandtab:cinoptions=(s,U1,m1
#include "moc_kcmcddb.cpp"

View file

@ -0,0 +1,54 @@
/*
Copyright (C) 2002 Rik Hemsley (rikkus) <rik@kde.org>
Copyright (C) 2002 Benjamin Meyer <ben-devel@meyerhome.net>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#ifndef KCMCDDB_H
#define KCMCDDB_H
#include <kcmodule.h>
#include "libkcddb/kcddbconfig.h"
class CDDBConfigWidget;
class CDDBModule : public KCModule
{
Q_OBJECT
public:
CDDBModule(QWidget * parent, const QVariantList &);
public slots:
void defaults();
void save();
void load();
protected:
void checkSettings() const;
void updateWidgetsFromConfig(const KCDDB::Config &);
private:
CDDBConfigWidget * widget_;
};
#endif // KCMCDDB_H
// vim:tabstop=2:shiftwidth=2:expandtab:cinoptions=(s,U1,m1

View file

@ -0,0 +1,205 @@
[Desktop Entry]
Exec=kcmshell4 libkcddb
Icon=media-optical-audio
Type=Service
ServiceTypes=KCModule
X-KDE-System-Settings-Parent-Category=audio-and-video
X-KDE-Library=kcm_cddb
X-KDE-ParentApp=kcontrol
X-DocPath=kcontrol/cddbretrieval/index.html
Name=CDDB Retrieval
Name[bg]=Изтегляне на данни от CDDB
Name[bs]=Dobavljanje iz CDDBa
Name[ca]=Recuperació CDDB
Name[ca@valencia]=Recuperació CDDB
Name[cs]=Získání CDDB
Name[da]=CDDB-hentning
Name[de]=CDDB-Abfrage
Name[el]=Ανάκτηση CDDB
Name[en_GB]=CDDB Retrieval
Name[es]=Recuperación de CDDB
Name[et]=CDDB ülekanded
Name[fi]=CDDB-haku
Name[fr]=Recherche CDDB
Name[ga]=Aisghabháil CDDB
Name[gl]=Obtención CDDB
Name[hu]=CDDB letöltés
Name[ia]=Recuperationde CDDB
Name[is]=CDDB-sækni
Name[it]=Recupero CDDB
Name[ja]=CDDB
Name[kk]=CDDB деректерді алу
Name[km]= CDDB
Name[ko]=CDDB
Name[lt]=CDDB atsisiuntimas
Name[mr]=CDDB -
Name[nb]=CDDB-henting
Name[nds]=CDDB-Affraag
Name[nl]=CDDB-informatie
Name[nn]=CDDB-henting
Name[pa]=CDDB
Name[pl]=Pobieranie z CDDB
Name[pt]=Transferência de CDDB
Name[pt_BR]=Recuperação do CDDB
Name[ro]=Preluare CDDB
Name[ru]=Доступ к CDDB
Name[sk]=Informácie z CDDB
Name[sl]=Pridobivanje CDDB
Name[sr]=Добављање из ЦДДБа
Name[sr@ijekavian]=Добављање из ЦДДБа
Name[sr@ijekavianlatin]=Dobavljanje iz CDDBa
Name[sr@latin]=Dobavljanje iz CDDBa
Name[sv]=Hämta från CDDB
Name[tr]=CDDB Erişimi
Name[uk]=Отримання з CDDB
Name[x-test]=xxCDDB Retrievalxx
Name[zh_CN]=CDDB
Name[zh_TW]=CDDB
GenericName=CDDB Configuration
GenericName[bg]=Настройки на CDDB
GenericName[bs]=Konfiguracija CDDBa
GenericName[ca]=Configuració CDDB
GenericName[ca@valencia]=Configuració CDDB
GenericName[cs]=Nastavení CDDB
GenericName[da]=CDDB-indstilling
GenericName[de]=CDDB-Einrichtung
GenericName[el]=Διαμόρφωση CDDB
GenericName[en_GB]=CDDB Configuration
GenericName[es]=Configuración de CDDB
GenericName[et]=CDDB seadistamine
GenericName[fi]=CDDB-asetukset
GenericName[fr]=Configuration CDDB
GenericName[ga]=Cumraíocht CDDB
GenericName[gl]=Configuración da CDDB
GenericName[hu]=CDDB beállítás
GenericName[ia]=Configuration de CDDB
GenericName[is]=Stillingar CDDB
GenericName[it]=Configurazione CDDB
GenericName[ja]=CDDB
GenericName[kk]=CDDB конфигурациясы
GenericName[km]= CDDB
GenericName[ko]=CDDB
GenericName[lt]=CDDB konfigūravimas
GenericName[mr]=CDDB
GenericName[nb]=CDDB-oppsett
GenericName[nds]=CDDB-Instellen
GenericName[nl]=CDDB-instellingen
GenericName[nn]=CDDB-oppsett
GenericName[pa]=CDDB
GenericName[pl]=Ustawienia CDDB
GenericName[pt]=Configuração do CDDB
GenericName[pt_BR]=Configuração do CDDB
GenericName[ro]=Configurare CDDB
GenericName[ru]=Настройка CDDB
GenericName[sk]=Nastavenie CDDB
GenericName[sl]=Nastavitve CDDB
GenericName[sr]=Постава ЦДДБа
GenericName[sr@ijekavian]=Постава ЦДДБа
GenericName[sr@ijekavianlatin]=Postava CDDBa
GenericName[sr@latin]=Postava CDDBa
GenericName[sv]=CDDB-inställning
GenericName[tr]=CDDB Yapılandırması
GenericName[ug]=CDDB سەپلىمىسى
GenericName[uk]=Налаштування CDDB
GenericName[x-test]=xxCDDB Configurationxx
GenericName[zh_CN]=CDDB
GenericName[zh_TW]=CDDB
Comment=Configure the CDDB Retrieval
Comment[bg]=Настройки на изтегляне на данни от CDDB
Comment[bs]=Podesite dobavljanje iz CDDBa
Comment[ca]=Configura la recuperació CDDB
Comment[ca@valencia]=Configura la recuperació CDDB
Comment[cs]=Nastavení stahování z CDDB
Comment[da]=Indstil hentning via CDDB
Comment[de]=CDDB-Abfrage einrichten
Comment[el]=Διαμόρφωση της ανάκτησης CDDB
Comment[en_GB]=Configure the CDDB Retrieval
Comment[es]=Configurar la recuperación de CDDB
Comment[et]=CDDB ülekannete seadistamine
Comment[fi]=Aseta CDDB-haku
Comment[fr]=Configurer la recherche CDDB
Comment[ga]=Cumraigh aisghabháil CDDB
Comment[gl]=Configurar a recuperación de CDDB
Comment[hu]=A CDDB letöltés beállítása
Comment[ia]=Configura le Recuperation de CDDB
Comment[is]=Stilla CDDB sækni
Comment[it]=Configura il recupero CDDB
Comment[ja]=CDDB
Comment[kk]=CDDB деректер алуды баптау
Comment[km]= CDDB
Comment[ko]=CDDB
Comment[lt]=Konfigūruoti CDDB atsisiuntimą
Comment[mr]=CDDB -
Comment[nb]=Oppsett av CDDB-henting
Comment[nds]=CDDB-Affraag instellen
Comment[nl]=Ophalen van CDDB-informatie instellen
Comment[nn]=Oppsett av CDDB-henting
Comment[pl]=Ustawienia pobierania danych z CDDB
Comment[pt]=Configurar a Transferência de CDDB
Comment[pt_BR]=Configurar a recuperação do CDDB
Comment[ro]=Configurează preluarea CDDB
Comment[ru]=Настройка CDDB
Comment[sk]=Nastavenie informácií z CDDB
Comment[sl]=Nastavi pridobivanje CDDB
Comment[sr]=Подесите добављање из ЦДДБа
Comment[sr@ijekavian]=Подесите добављање из ЦДДБа
Comment[sr@ijekavianlatin]=Podesite dobavljanje iz CDDBa
Comment[sr@latin]=Podesite dobavljanje iz CDDBa
Comment[sv]=Anpassa hämtning från CDDB
Comment[tr]=CDDB Erişimini Yapılandır
Comment[uk]=Налаштування отримання з CDDB
Comment[x-test]=xxConfigure the CDDB Retrievalxx
Comment[zh_CN]= CDDB
Comment[zh_TW]=CDDB
Keywords=cddb;
Keywords[ast]=cddb;
Keywords[bg]=cddb;данни;диск;
Keywords[bs]=cddb;
Keywords[ca]=cddb;
Keywords[ca@valencia]=cddb;
Keywords[cs]=cddb;
Keywords[da]=cddb;
Keywords[de]=cddb;
Keywords[el]=cddb;
Keywords[en_GB]=cddb;
Keywords[es]=cddb;
Keywords[et]=cddb;
Keywords[fi]=cddb;
Keywords[fr]=cddb ;
Keywords[ga]=cddb;
Keywords[gl]=cddb;
Keywords[hu]=cddb;
Keywords[ia]=cddb;
Keywords[is]=cddb;
Keywords[it]=cddb;
Keywords[kk]=cddb;
Keywords[ko]=cddb;
Keywords[mr]=cddb;
Keywords[nb]=cddb;
Keywords[nds]=CDDB;cddb;
Keywords[nl]=cddb;
Keywords[pl]=cddb;
Keywords[pt]=cddb;
Keywords[pt_BR]=cddb;
Keywords[ro]=cddb;
Keywords[ru]=cddb;
Keywords[sk]=cddb;
Keywords[sl]=cddb;
Keywords[sr]=CDDB;ЦДДБ;
Keywords[sr@ijekavian]=CDDB;ЦДДБ;
Keywords[sr@ijekavianlatin]=CDDB;CDDB;
Keywords[sr@latin]=CDDB;CDDB;
Keywords[sv]=cddb;
Keywords[tr]=cddb;
Keywords[ug]=cddb;
Keywords[uk]=cddb;
Keywords[x-test]=xxcddbxx;
Keywords[zh_CN]=cddb;
Keywords[zh_TW]=cddb;
Categories=Qt;KDE;X-KDE-settings-sound;

View file

@ -0,0 +1,66 @@
include_directories(
${CMAKE_CURRENT_BINARY_DIR}
)
########### next target ###############
set(kcddb_LIB_SRCS ${libmusicbrainz_SRCS}
cache.cpp
cdinfo.cpp
kcddbconfig.cpp
client.cpp
kcddb.cpp
cddb.cpp
lookup.cpp
cddbplookup.cpp
synccddbplookup.cpp
asynccddbplookup.cpp
httplookup.cpp
synchttplookup.cpp
asynchttplookup.cpp
smtpsubmit.cpp
asyncsmtpsubmit.cpp
syncsmtpsubmit.cpp
submit.cpp
sites.cpp
httpsubmit.cpp
asynchttpsubmit.cpp
synchttpsubmit.cpp
categories.cpp
genres.cpp
cdinfodialog.cpp
cdinfoencodingwidget.cpp
cdinfodialog.ui
cdinfoencodingwidget.ui
)
kde4_add_kcfg_files(kcddb_LIB_SRCS configbase.kcfgc )
add_library(kcddb SHARED ${kcddb_LIB_SRCS})
target_link_libraries(kcddb ${KDE4_KDEUI_LIBS} ${KDE4_KIO_LIBS})
if(MUSICBRAINZ5_FOUND)
target_link_libraries(kcddb ${MUSICBRAINZ5_LIBRARIES})
endif()
set_target_properties(kcddb PROPERTIES
VERSION ${GENERIC_LIB_VERSION}
SOVERSION ${GENERIC_LIB_SOVERSION}
)
########### install files ###############
install(FILES
cdinfo.h
cdinfodialog.h
client.h
genres.h
kcddbconfig.h
kcddb.h
kcddb_export.h
${CMAKE_CURRENT_BINARY_DIR}/configbase.h
DESTINATION ${INCLUDE_INSTALL_DIR}/libkcddb COMPONENT Devel)
install( FILES libkcddb.kcfg DESTINATION ${KCFG_INSTALL_DIR})
install(TARGETS kcddb EXPORT LibkcddbTargets ${INSTALL_TARGETS_DEFAULT_ARGS})

View file

@ -0,0 +1,342 @@
/*
Copyright (C) 2002 Rik Hemsley (rikkus) <rik@kde.org>
Copyright (C) 2002 Benjamin Meyer <ben-devel@meyerhome.net>
Copyright (C) 2005 Richard Lärkäng <nouseforaname@home.se>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#include "asynccddbplookup.h"
#include <kdebug.h>
#include <ksocketfactory.h>
namespace KCDDB
{
AsyncCDDBPLookup::AsyncCDDBPLookup()
: CDDBPLookup(),
state_(Idle)
{
}
AsyncCDDBPLookup::~AsyncCDDBPLookup()
{
}
Result
AsyncCDDBPLookup::lookup
(
const QString & hostname,
uint port,
const TrackOffsetList & trackOffsetList
)
{
socket_ = KSocketFactory::connectToHost(QLatin1String( "cddbp" ), hostname, port);
connect (socket_, SIGNAL(error(QAbstractSocket::SocketError)), SLOT(slotGotError(QAbstractSocket::SocketError)));
connect (socket_, SIGNAL(connected()),
SLOT(slotConnectionSuccess()) );
connect (socket_, SIGNAL(readyRead()), SLOT(slotReadyRead()) );
trackOffsetList_ = trackOffsetList;
state_ = WaitingForConnection;
return Success;
}
void
AsyncCDDBPLookup::slotGotError(QAbstractSocket::SocketError error)
{
state_ = Idle;
if ( error == QAbstractSocket::HostNotFoundError )
emit finished( HostNotFound );
else if ( error == QAbstractSocket::SocketTimeoutError )
emit finished( NoResponse );
else
emit finished( UnknownError );
}
void
AsyncCDDBPLookup::slotConnectionSuccess()
{
kDebug(60010) << "Connection successful";
state_ = WaitingForGreeting;
}
void
AsyncCDDBPLookup::slotReadyRead()
{
kDebug(60010) << "Ready to read. State: " << stateToString();
while ( Idle != state_ && isConnected() && socket_->canReadLine() )
read();
}
void
AsyncCDDBPLookup::read()
{
switch ( state_ )
{
case WaitingForGreeting:
if ( !parseGreeting( readLine() ) )
{
result_ = ServerError;
doQuit();
return;
}
doHandshake();
break;
case WaitingForHandshake:
if ( !parseHandshake( readLine() ) )
{
result_ = ServerError;
doQuit();
return;
}
doProto();
break;
case WaitingForProtoResponse:
// Ignore the response for now
readLine();
doQuery();
break;
case WaitingForQueryResponse:
result_ = parseQuery( readLine() );
switch ( result_ )
{
case Success:
requestCDInfoForMatch();
break;
case MultipleRecordFound:
state_ = WaitingForMoreMatches;
break;
default: // Error :(
doQuit();
return;
}
break;
case WaitingForMoreMatches:
{
QString line = readLine();
if (line.startsWith(QLatin1String( "." )))
requestCDInfoForMatch();
else
parseExtraMatch( line );
}
break;
case WaitingForCDInfoResponse:
{
Result result = parseRead( readLine() );
if ( Success != result )
{
result_ = result;
doQuit();
return;
}
state_ = WaitingForCDInfoData;
}
break;
case WaitingForCDInfoData:
{
QString line = readLine();
if (line.startsWith(QLatin1String( "." )))
{
parseCDInfoData();
requestCDInfoForMatch();
}
else
cdInfoBuffer_ << line;
}
break;
case WaitingForQuitResponse:
state_ = Idle;
char c;
while ( socket_->bytesAvailable() )
socket_->getChar(&c);
close();
emit finished( result_ );
break;
default:
break;
}
}
QString
AsyncCDDBPLookup::readLine()
{
return QString::fromUtf8(socket_->readLine());
}
void
AsyncCDDBPLookup::doHandshake()
{
sendHandshake();
state_ = WaitingForHandshake;
}
void
AsyncCDDBPLookup::doProto()
{
sendProto();
state_ = WaitingForProtoResponse;
}
void
AsyncCDDBPLookup::doQuery()
{
sendQuery();
state_ = WaitingForQueryResponse;
}
void
AsyncCDDBPLookup::requestCDInfoForMatch()
{
if (matchList_.isEmpty())
{
result_ = cdInfoList_.isEmpty()? NoRecordFound : Success;
doQuit();
return;
}
CDDBMatch match = matchList_.takeFirst();
sendRead( match );
state_ = WaitingForCDInfoResponse;
}
void
AsyncCDDBPLookup::parseCDInfoData()
{
CDInfo info;
if (info.load( cdInfoBuffer_ ))
{
info.set( QLatin1String( "category" ), category_ );
info.set( QLatin1String( "discid" ), discid_ );
info.set( QLatin1String( "source" ), QLatin1String( "freedb" ) );
cdInfoList_.append( info );
}
cdInfoBuffer_.clear();
}
void
AsyncCDDBPLookup::doQuit()
{
state_ = WaitingForQuitResponse;
sendQuit();
}
QString
AsyncCDDBPLookup::stateToString() const
{
switch (state_)
{
case Idle:
return QLatin1String( "Idle" );
break;
case WaitingForConnection:
return QLatin1String( "WaitingForConnection" );
break;
case WaitingForGreeting:
return QLatin1String( "WaitingForGreeting" );
break;
case WaitingForProtoResponse:
return QLatin1String( "WaitingForProtoResponse" );
break;
case WaitingForHandshake:
return QLatin1String( "WaitingForHandshake" );
break;
case WaitingForQueryResponse:
return QLatin1String( "WaitingForQueryResponse" );
break;
case WaitingForMoreMatches:
return QLatin1String( "WaitingForMoreMatches" );
break;
case WaitingForCDInfoResponse:
return QLatin1String( "WaitingForCDInfoResponse" );
break;
case WaitingForCDInfoData:
return QLatin1String( "WaitingForCDInfoData" );
break;
case WaitingForQuitResponse:
return QLatin1String( "WaitingForQuitResponse" );
break;
default:
return QLatin1String( "Unknown" );
break;
}
}
}
#include "moc_asynccddbplookup.cpp"
// vim:tabstop=2:shiftwidth=2:expandtab:cinoptions=(s,U1,m1

View file

@ -0,0 +1,93 @@
/*
Copyright (C) 2002 Rik Hemsley (rikkus) <rik@kde.org>
Copyright (C) 2002 Benjamin Meyer <ben-devel@meyerhome.net>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#ifndef KCDDB_ASYNC_CDDBP_LOOKUP_H
#define KCDDB_ASYNC_CDDBP_LOOKUP_H
#include "cddbplookup.h"
namespace KCDDB
{
class AsyncCDDBPLookup : public CDDBPLookup
{
Q_OBJECT
public:
enum State
{
Idle,
WaitingForConnection,
WaitingForGreeting,
WaitingForHandshake,
WaitingForProtoResponse,
WaitingForQueryResponse,
WaitingForMoreMatches,
WaitingForCDInfoResponse,
WaitingForCDInfoData,
WaitingForQuitResponse
};
AsyncCDDBPLookup();
virtual ~AsyncCDDBPLookup();
Result lookup( const QString &, uint, const TrackOffsetList & );
signals:
void finished( KCDDB::Result );
void quit( Result );
protected slots:
void slotGotError(QAbstractSocket::SocketError error);
void slotConnectionSuccess();
void slotReadyRead();
protected:
void doHandshake();
void doProto();
void doQuery();
void doQuit();
bool parseQueryResponse( const QString & );
void requestCDInfoForMatch();
bool parseCDInfoResponse( const QString & );
void parseCDInfoData();
void read();
QString readLine();
QString stateToString() const;
private:
State state_;
Result result_;
QStringList cdInfoBuffer_;
};
}
#endif // KCDDB_ASYNC_CDDBP_LOOKUP_H
// vim:tabstop=2:shiftwidth=2:expandtab:cinoptions=(s,U1,m1

View file

@ -0,0 +1,152 @@
/*
Copyright (C) 2002 Rik Hemsley (rikkus) <rik@kde.org>
Copyright (C) 2002 Benjamin Meyer <ben-devel@meyerhome.net>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#include "asynchttplookup.h"
#include <qstringlist.h>
#include <qapplication.h>
#include <kdebug.h>
#include <kio/job.h>
namespace KCDDB
{
AsyncHTTPLookup::AsyncHTTPLookup()
: HTTPLookup()
{
block_ = false;
}
AsyncHTTPLookup::~AsyncHTTPLookup()
{
// Empty.
}
Result
AsyncHTTPLookup::lookup
(
const QString & hostName,
uint port,
const TrackOffsetList & trackOffsetList
)
{
trackOffsetList_ = trackOffsetList;
connect( this, SIGNAL(queryReady()), SLOT(slotQueryReady()) );
connect( this, SIGNAL(readReady()), SLOT(requestCDInfoForMatch()) );
initURL( hostName, port );
// Run a query.
result_ = runQuery();
return result_;
}
Result
AsyncHTTPLookup::runQuery()
{
data_ = QByteArray();
state_ = WaitingForQueryResponse;
result_ = sendQuery();
return result_;
}
void
AsyncHTTPLookup::slotQueryReady()
{
kDebug(60010) << "Matches Found: " << matchList_.count();
if ( Success != result_ )
{
emit finished( result_ );
return;
}
requestCDInfoForMatch();
}
void
AsyncHTTPLookup::requestCDInfoForMatch()
{
if ( matchList_.isEmpty() )
{
result_ = cdInfoList_.isEmpty()? NoRecordFound : Success;
emit finished( result_ );
return;
}
CDDBMatch match = matchList_.takeFirst();
data_ = QByteArray();
state_ = WaitingForReadResponse;
result_ = sendRead( match );
if ( Success != result_ )
emit finished( result_ );
}
void
AsyncHTTPLookup::slotData( KIO::Job *, const QByteArray &data )
{
if (data.size() > 0)
data_.append(data);
}
void
AsyncHTTPLookup::slotResult( KJob *job )
{
if ( 0 != job->error() )
{
result_ = ServerError;
if ( !block_ )
emit queryReady();
return;
}
jobFinished();
}
Result
AsyncHTTPLookup::fetchURL()
{
kDebug(60010) << "About to fetch: " << cgiURL_.url();
KIO::TransferJob* job = KIO::get( cgiURL_, KIO::NoReload, KIO::HideProgressInfo );
if ( 0 == job )
return ServerError;
connect( job, SIGNAL(data(KIO::Job*,QByteArray)),
SLOT(slotData(KIO::Job*,QByteArray)) );
connect( job, SIGNAL(result(KJob*)),
SLOT(slotResult(KJob*)) );
return Success;
}
}
#include "moc_asynchttplookup.cpp"
// vim:tabstop=2:shiftwidth=2:expandtab:cinoptions=(s,U1,m1

View file

@ -0,0 +1,64 @@
/*
Copyright (C) 2002 Rik Hemsley (rikkus) <rik@kde.org>
Copyright (C) 2002 Benjamin Meyer <ben-devel@meyerhome.net>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#ifndef KCDDB_ASYNC_HTTP_LOOKUP_H
#define KCDDB_ASYNC_HTTP_LOOKUP_H
#include "httplookup.h"
class KJob;
namespace KCDDB
{
class AsyncHTTPLookup : public HTTPLookup
{
Q_OBJECT
public:
AsyncHTTPLookup();
virtual ~AsyncHTTPLookup();
Result lookup( const QString &, uint, const TrackOffsetList & );
CDInfoList lookupResponse() const;
signals:
void finished( KCDDB::Result );
protected slots:
void slotQueryReady();
void requestCDInfoForMatch();
void slotData( KIO::Job *, const QByteArray & );
void slotResult( KJob * );
protected:
virtual Result fetchURL();
Result runQuery();
};
}
#endif // KCDDB_ASYNC_HTTP_LOOKUP_H
// vim:tabstop=2:shiftwidth=2:expandtab:cinoptions=(s,U1,m1

View file

@ -0,0 +1,56 @@
/*
Copyright (C) 2003 Richard Lärkäng <nouseforaname@home.se>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#include "asynchttpsubmit.h"
#include <kio/job.h>
#include <kdebug.h>
namespace KCDDB
{
AsyncHTTPSubmit::AsyncHTTPSubmit(const QString& from, const QString& hostname, uint port)
: HTTPSubmit(from, hostname, port)
{
}
AsyncHTTPSubmit::~AsyncHTTPSubmit()
{
}
Result AsyncHTTPSubmit::runJob(KIO::Job* job)
{
connect(job, SIGNAL(result(KJob*)), SLOT(slotFinished(KJob*)));
return Success;
}
void AsyncHTTPSubmit::slotFinished(KJob* job)
{
kDebug() << "Finished";
if ( job->error()==0 )
emit finished( Success );
else
emit finished( UnknownError );
}
}
#include "moc_asynchttpsubmit.cpp"

View file

@ -0,0 +1,46 @@
#ifndef ASYNCHTTPSUBMIT_H
#define ASYNCHTTPSUBMIT_H
/*
Copyright (C) 2003 Richard Lärkäng <nouseforaname@home.se>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#include "httpsubmit.h"
class KJob;
namespace KCDDB
{
class AsyncHTTPSubmit : public HTTPSubmit
{
Q_OBJECT
public:
AsyncHTTPSubmit(const QString& from, const QString& hostname, uint port);
virtual ~AsyncHTTPSubmit();
signals:
void finished( KCDDB::Result );
protected:
virtual Result runJob(KIO::Job* job);
private slots:
void slotFinished(KJob*);
} ;
}
#endif // ASYNCHTTPSUBMIT_H

View file

@ -0,0 +1,60 @@
/*
Copyright (C) 2003 Richard Lärkäng <nouseforaname@home.se>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#include "asyncsmtpsubmit.h"
#include "cdinfo.h"
#include <kdebug.h>
#include <kio/job.h>
namespace KCDDB
{
AsyncSMTPSubmit::AsyncSMTPSubmit(const QString& hostname, uint port,
const QString& username, const QString& from, const QString& to )
: SMTPSubmit( hostname, port, username, from, to )
{
}
AsyncSMTPSubmit::~AsyncSMTPSubmit()
{
}
Result AsyncSMTPSubmit::runJob(KIO::Job* job)
{
connect( job, SIGNAL(result(KJob*)),
this, SLOT(slotDone(KJob*)) );
return Success;
}
void AsyncSMTPSubmit::slotDone( KJob* job )
{
kDebug(60010) ;
if ( job->error()==0 )
emit finished( Success );
else
emit finished( UnknownError );
}
}
#include "moc_asyncsmtpsubmit.cpp"

View file

@ -0,0 +1,51 @@
#ifndef ASYNCSMTPSUBMIT_H
#define ASYNCSMTPSUBMIT_H
/*
Copyright (C) 2003-2004 Richard Lärkäng <nouseforaname@home.se>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#include "smtpsubmit.h"
class KJob;
namespace KIO
{
class Job;
}
namespace KCDDB
{
class AsyncSMTPSubmit : public SMTPSubmit
{
Q_OBJECT
public:
AsyncSMTPSubmit(const QString& hostname, uint port, const QString& username,
const QString& from, const QString& to);
virtual ~AsyncSMTPSubmit();
signals:
void finished( KCDDB::Result );
protected slots:
void slotDone( KJob * );
protected:
virtual Result runJob(KIO::Job* job);
} ;
}
#endif // ASYNCSMTPSUBMIT_H
// vim:tabstop=2:shiftwidth=2:expandtab:cinoptions=(s,U1,m1

147
libkcddb/libkcddb/cache.cpp Normal file
View file

@ -0,0 +1,147 @@
/*
Copyright (C) 2002 Rik Hemsley (rikkus) <rik@kde.org>
Copyright (C) 2002 Benjamin Meyer <ben-devel@meyerhome.net>
Copyright (C) 2002 Nadeem Hasan <nhasan@kde.org>
Copyright (C) 2007 Richard Lärkäng <nouseforaname@home.se>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#include "cache.h"
#include "kcddbconfig.h"
#include "cddb.h"
#include "config-musicbrainz.h"
#ifdef HAVE_MUSICBRAINZ5
#include "musicbrainz/musicbrainzlookup.h"
#endif
#include <kdebug.h>
#include <kstandarddirs.h>
#include <QFile>
#include <QDir>
#include <QTextStream>
namespace KCDDB
{
CDInfoList
Cache::lookup( const TrackOffsetList &offsetList, const Config& c )
{
QString cddbId = CDDB::trackOffsetListToId(offsetList);
kDebug(60010) << "Looking up " << cddbId << " in CDDB cache";
CDInfoList infoList;
infoList << CDDB::cacheFiles(offsetList, c);
#ifdef HAVE_MUSICBRAINZ5
infoList << MusicBrainzLookup::cacheFiles(offsetList, c);
#endif
return infoList;
}
void
Cache::store(const TrackOffsetList& offsetList, const CDInfoList& list, const Config& c)
{
foreach( const CDInfo &info, list )
{
store(offsetList, info, c);
}
}
void
Cache::store(const TrackOffsetList& offsetList, const CDInfo& info, const Config& c)
{
QString discid = info.get(QLatin1String( "discid" )).toString();
// Some entries from freedb could contain several discids separated
// by a ','. Store for each discid, but replace the discid line
// so it doesn't happen again.
QStringList discids = discid.split(QLatin1Char( ',' ));
if (discids.count() > 2)
{
foreach(const QString &newid, discids)
{
CDInfo newInfo = info;
newInfo.set(QLatin1String( "discid" ), newid);
store(offsetList, newInfo, c);
}
}
QString source = info.get(QLatin1String( "source" )).toString();
QString cacheDir;
QString cacheFile;
CDInfo newInfo = info;
if (source == QLatin1String( "freedb" ))
{
cacheDir = QLatin1Char( '/' ) + info.get(QLatin1String( "category" )).toString() + QLatin1Char( '/' );
cacheFile = discid;
}
else if (source == QLatin1String( "musicbrainz" ))
{
cacheDir = QLatin1String( "/musicbrainz/" );
cacheFile = discid;
}
else
{
if (source != QLatin1String( "user" ))
kWarning(60010) << "Unknown source " << source << " for CDInfo";
cacheDir = QLatin1String( "/user/" );
QString id = CDDB::trackOffsetListToId(offsetList);
cacheFile = id;
newInfo.set(QLatin1String( "discid" ), id);
}
const QStringList cacheLocations = c.cacheLocations();
if (!cacheLocations.isEmpty()) {
cacheDir = cacheLocations.first() + cacheDir;
QDir dir;
if (!dir.exists(cacheDir))
{
if (!dir.mkpath(cacheDir))
{
kWarning(60010) << "Couldn't create cache directory " << cacheDir;
return;
}
}
kDebug(60010) << "Storing " << cacheFile << " in CDDB cache";
QFile f(cacheDir + QLatin1Char( '/' ) + cacheFile);
if ( f.open(QIODevice::WriteOnly) )
{
QTextStream ts(&f);
ts.setCodec("UTF-8");
ts << newInfo.toString();
f.close();
}
} else {
kDebug(60010) << "There's no cache dir defined, not storing it";
}
}
}
// vim:tabstop=2:shiftwidth=2:expandtab:cinoptions=(s,U1,m1

49
libkcddb/libkcddb/cache.h Normal file
View file

@ -0,0 +1,49 @@
/*
Copyright (C) 2002 Rik Hemsley (rikkus) <rik@kde.org>
Copyright (C) 2002 Benjamin Meyer <ben-devel@meyerhome.net>
Copyright (C) 2002 Nadeem Hasan <nhasan@kde.org>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#ifndef KCDDB_CACHE_H
#define KCDDB_CACHE_H
#include <qpair.h>
#include <QString>
#include "kcddb.h"
#include "cdinfo.h"
#include <kdemacros.h>
namespace KCDDB
{
class Config;
class KCDDB_EXPORT Cache
{
public:
static CDInfoList lookup( const TrackOffsetList & , const Config & );
static void store( const TrackOffsetList &, const CDInfoList &, const Config & );
static void store( const TrackOffsetList &, const CDInfo &, const Config & );
private:
static QString fileName( const QString &category, const QString& discid, const QString &cacheDir );
};
}
#endif // KCDDB_CACHE_H
// vim:tabstop=2:shiftwidth=2:expandtab:cinoptions=(s,U1,m1

View file

@ -0,0 +1,51 @@
// Copyright (C) 2005 by Shaheed Haque (srhaque@iee.org). All rights reserved.
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
#include "categories.h"
#include <klocale.h>
KCDDB::Categories::Categories()
{
// These are only 11 Category values defined by CDDB. See
//
// http://www.freedb.org/modules.php?name=Sections&sop=viewarticle&artid=26
//
m_cddb << QLatin1String( "blues" ) << QLatin1String( "classical" ) << QLatin1String( "country" ) <<
QLatin1String( "data" ) << QLatin1String( "folk" ) << QLatin1String( "jazz" ) << QLatin1String( "misc" ) <<
QLatin1String( "newage" ) << QLatin1String( "reggae" ) << QLatin1String( "rock" ) << QLatin1String( "soundtrack" );
m_i18n << i18n("Blues") << i18n("Classical") << i18nc("music genre", "Country") <<
i18n("Data") << i18n("Folk") << i18n("Jazz") << i18n("Miscellaneous") <<
i18n("New Age") << i18n("Reggae") << i18n("Rock") << i18n("Soundtrack");
}
const QString KCDDB::Categories::cddb2i18n(const QString &category) const
{
int index = m_cddb.indexOf(category.trimmed());
if (index != -1)
{
return m_i18n[index];
}
else
{
return cddb2i18n(QLatin1String( "misc" ));
}
}
const QString KCDDB::Categories::i18n2cddb(const QString &category) const
{
int index = m_i18n.indexOf(category.trimmed());
if (index != -1)
{
return m_cddb[index];
}
else
{
return QLatin1String( "misc" );
}
}

View file

@ -0,0 +1,42 @@
// Copyright (C) 2005 by Shaheed Haque (srhaque@iee.org). All rights reserved.
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
#ifndef KCDDB_CATEGORIES_H
#define KCDDB_CATEGORIES_H
#include <QString>
#include <qstringlist.h>
namespace KCDDB
{
/**
* Category values defined by CDDB.
*/
class Categories
{
public:
Categories();
const QStringList &cddbList() const { return m_cddb; }
const QStringList &i18nList() const { return m_i18n; }
/**
* Lookup the CDDB category, and return the i18n'd version.
*/
const QString cddb2i18n(const QString &category) const;
/**
* Lookup the i18n category, and return the CDDB version.
*/
const QString i18n2cddb(const QString &category) const;
private:
QStringList m_cddb;
QStringList m_i18n;
};
}
#endif

157
libkcddb/libkcddb/cddb.cpp Normal file
View file

@ -0,0 +1,157 @@
/*
Copyright (C) 2002 Rik Hemsley (rikkus) <rik@kde.org>
Copyright (C) 2002 Benjamin Meyer <ben-devel@meyerhome.net>
CopyRight (C) 2002 Nadeem Hasan <nhasan@kde.org>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#include "cddb.h"
#include "categories.h"
#include <qstringlist.h>
#include <kdebug.h>
#include <kstringhandler.h>
#include <klocale.h>
namespace KCDDB
{
CDDB::CDDB()
: user_( QLatin1String( "libkcddb-user" ) ),
localHostName_( QLatin1String( "localHost" ) ),
readOnly_( false )
{
}
CDDB::~CDDB()
{
// Empty.
}
QString
CDDB::trackOffsetListToId()
{
return trackOffsetListToId( trackOffsetList_ );
}
QString
CDDB::trackOffsetListToId( const TrackOffsetList & list )
{
// Taken from version by Michael Matz in kio_audiocd.
unsigned int id = 0;
if ( list.isEmpty() )
return QString();
int numTracks = list.count() - 1;
// The last two in the list are disc begin and disc end.
for ( int i = numTracks-1; i >= 0; i-- )
{
int n = list[ i ]/75;
while ( n > 0 )
{
id += n % 10;
n /= 10;
}
}
unsigned int l = list[numTracks] / 75;
l -= list[0] / 75;
id = ( ( id % 255 ) << 24 ) | ( l << 8 ) | numTracks;
return QString::number( id, 16 ).rightJustified( 8, QLatin1Char( '0' ) );
}
QString
CDDB::trackOffsetListToString()
{
QString ret;
uint numTracks = trackOffsetList_.count()-1;
// Disc start.
ret.append( QString::number( numTracks ) );
ret.append( QLatin1String( " " ) );
for ( uint i = 0; i < numTracks; i++ )
{
ret.append( QString::number( trackOffsetList_[ i ] ) );
ret.append( QLatin1String( " " ) );
}
unsigned int discLengthInSec = ( trackOffsetList_[ numTracks ] ) / 75;
ret.append( QString::number( discLengthInSec ) );
return ret;
}
uint
CDDB::statusCode( const QString & line )
{
QStringList tokenList = line.split(QLatin1Char( ' ' ), QString::SkipEmptyParts );
uint serverStatus = tokenList[ 0 ].toUInt();
return serverStatus;
}
CDInfoList
CDDB::cacheFiles(const TrackOffsetList &offsetList, const Config& config )
{
Categories c;
QStringList categories = c.cddbList();
// Also load user-created entries
categories << QLatin1String( "user" );
CDInfoList infoList;
QStringList cddbCacheDirs = config.cacheLocations();
for (QStringList::const_iterator cddbCacheDir = cddbCacheDirs.constBegin();
cddbCacheDir != cddbCacheDirs.constEnd(); ++cddbCacheDir)
{
foreach(const QString &category, categories)
{
QFile f( *cddbCacheDir + QLatin1Char( '/' ) + category + QLatin1Char( '/' ) + trackOffsetListToId(offsetList) );
if ( f.exists() && f.open(QIODevice::ReadOnly) )
{
QTextStream ts(&f);
ts.setCodec("UTF-8");
QString cddbData = ts.readAll();
f.close();
CDInfo info;
info.load(cddbData);
if (category != QLatin1String( "user" ))
{
info.set(Category,category);
info.set(QLatin1String( "source" ), QLatin1String( "freedb" ));
}
else
{
info.set(QLatin1String( "source" ), QLatin1String( "user" ));
}
infoList.append( info );
}
}
}
return infoList;
}
}
// vim:tabstop=2:shiftwidth=2:expandtab:cinoptions=(s,U1,m1

63
libkcddb/libkcddb/cddb.h Normal file
View file

@ -0,0 +1,63 @@
/*
Copyright (C) 2002 Rik Hemsley (rikkus) <rik@kde.org>
Copyright (C) 2002 Benjamin Meyer <ben-devel@meyerhome.net>
CopyRight (C) 2002 Nadeem Hasan <nhasan@kde.org>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#ifndef KCDDB_CDDB_H
#define KCDDB_CDDB_H
#include <QtCore/QString>
#include <QtCore/QList>
#include <libkcddb/kcddb.h>
#include <libkcddb/cdinfo.h>
#include <libkcddb/kcddbconfig.h>
namespace KCDDB
{
class CDDB
{
public:
CDDB();
virtual ~CDDB();
static QString trackOffsetListToId( const TrackOffsetList & );
static QString clientName() { return QLatin1String("libkcddb"); }
static QString clientVersion() { return QLatin1String("0.5"); }
static uint statusCode( const QString & );
static CDInfoList cacheFiles(const TrackOffsetList &, const Config& );
protected:
QString trackOffsetListToId();
QString trackOffsetListToString();
QString user_;
QString localHostName_;
bool readOnly_;
TrackOffsetList trackOffsetList_;
};
}
#endif // KCDDB_CDDB_H
// vim:tabstop=2:shiftwidth=2:expandtab:cinoptions=(s,U1,m1

View file

@ -0,0 +1,157 @@
/*
Copyright ( C ) 2002 Rik Hemsley ( rikkus ) <rik@kde.org>
Copyright ( C ) 2002 Benjamin Meyer <ben-devel@meyerhome.net>
Copyright ( C ) 2002 Nadeem Hasan <nhasan@kde.org>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or ( at your option ) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#include "cddbplookup.h"
#include <kdebug.h>
#include <qbytearray.h>
namespace KCDDB
{
CDDBPLookup::CDDBPLookup()
: Lookup()
, socket_(0)
{
}
CDDBPLookup::~CDDBPLookup()
{
if (socket_)
delete socket_;
}
void
CDDBPLookup::sendHandshake()
{
QString handshake = QString::fromLatin1( "cddb hello %1 %2 %3 %4" )
.arg( user_ )
.arg( localHostName_ )
.arg( clientName() )
.arg( clientVersion() );
writeLine( handshake );
}
void
CDDBPLookup::sendProto()
{
writeLine( QLatin1String( "proto 6" ) );
}
void
CDDBPLookup::sendQuery()
{
QString query = QString::fromLatin1( "cddb query %1 %2" )
.arg( trackOffsetListToId() )
.arg( trackOffsetListToString() );
writeLine( query );
}
void
CDDBPLookup::sendRead( const CDDBMatch & match )
{
category_ = match.first;
discid_ = match.second;
QString readRequest = QString::fromLatin1( "cddb read %1 %2" )
.arg( category_ )
.arg( discid_ );
writeLine( readRequest );
}
void
CDDBPLookup::sendQuit()
{
writeLine( QLatin1String( "quit" ) );
}
void
CDDBPLookup::close()
{
kDebug(60010) << "Disconnect from server...";
if ( isConnected() )
{
socket_->close();
}
}
bool
CDDBPLookup::parseGreeting( const QString & line )
{
uint serverStatus = statusCode( line );
if ( 200 == serverStatus )
{
kDebug(60010) << "Server response: read-only";
readOnly_ = true;
}
else if ( 201 == serverStatus )
{
kDebug(60010) << "Server response: read-write";
}
else
{
kDebug(60010) << "Server response: bugger off";
return false;
}
return true;
}
bool
CDDBPLookup::parseHandshake( const QString & line )
{
uint serverStatus = statusCode( line );
if ( ( 200 != serverStatus ) && ( 402 != serverStatus ) )
{
kDebug(60010) << "Handshake was too tight. Letting go.";
return false;
}
kDebug(60010) << "Handshake was warm and firm";
return true;
}
qint64
CDDBPLookup::writeLine( const QString & line )
{
if ( !isConnected() )
{
kDebug(60010) << "socket status: " << socket_->state();
return -1;
}
kDebug(60010) << "WRITE: [" << line << "]";
QByteArray buf(line.toUtf8());
buf.append( '\n' );
return socket_->write( buf );
}
}
// vim:tabstop=2:shiftwidth=2:expandtab:cinoptions=(s,U1,m1

View file

@ -0,0 +1,59 @@
/*
Copyright (C) 2002 Rik Hemsley ( rikkus ) <rik@kde.org>
Copyright (C) 2002 Benjamin Meyer <ben-devel@meyerhome.net>
Copyright (C) 2002 Nadeem Hasan <nhasan@kde.org>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or ( at your option ) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#ifndef KCDDB_CDDBP_LOOKUP_H
#define KCDDB_CDDBP_LOOKUP_H
#include <qtcpsocket.h>
#include "lookup.h"
namespace KCDDB
{
class CDDBPLookup : public Lookup
{
public:
CDDBPLookup();
virtual ~CDDBPLookup();
void sendHandshake();
void sendProto();
void sendQuery();
void sendRead( const CDDBMatch & );
void sendQuit();
void close();
protected:
qint64 writeLine( const QString & );
bool parseGreeting( const QString & );
bool parseHandshake( const QString & );
bool isConnected()
{ return QAbstractSocket::ConnectedState == socket_->state(); }
QTcpSocket* socket_;
};
}
#endif
// vim:tabstop=2:shiftwidth=2:expandtab:cinoptions=(s,U1,m1

View file

@ -0,0 +1,599 @@
/*
Copyright (C) 2002 Rik Hemsley (rikkus) <rik@kde.org>
Copyright (C) 2002-2005 Benjamin Meyer <ben-devel@meyerhome.net>
Copyright (C) 2002-2004 Nadeem Hasan <nhasan@nadmm.com>
Copyright (C) 2006 Richard Lärkäng <nouseforaname@home.se>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#include "cdinfo.h"
#include "client.h"
#include "cddb.h"
#include <kdebug.h>
#include <kstringhandler.h>
#include <QMap>
namespace KCDDB
{
class InfoBasePrivate {
public:
/**
* Creates a line in the form NAME=VALUE, and splits it into several
* lines if the line gets longer than 256 chars
*/
static QString
createLine(const QString& name, const QString& value)
{
Q_ASSERT(name.length() < 254);
int maxLength = 256 - name.length() - 2;
QString tmpValue = escape(value);
QString lines;
while (tmpValue.length() > maxLength)
{
lines += QString::fromLatin1("%1=%2\n").arg(name,tmpValue.left(maxLength));
tmpValue = tmpValue.mid(maxLength);
}
lines += QString::fromLatin1("%1=%2\n").arg(name,tmpValue);
return lines;
}
/**
* escape's string for CDDB processing
*/
static QString
escape( const QString &value )
{
QString s = value;
s.replace( QLatin1String( "\\" ), QLatin1String( "\\\\" ) );
s.replace( QLatin1String( "\n" ), QLatin1String( "\\n" ) );
s.replace( QLatin1String( "\t" ), QLatin1String( "\\t" ) );
return s;
}
/**
* fixes an escaped string that has been CDDB processed
*/
static QString
unescape( const QString &value )
{
QString s = value;
s.replace( QLatin1String( "\\n" ), QLatin1String( "\n" ) );
s.replace( QLatin1String( "\\t" ), QLatin1String( "\t" ) );
s.replace( QLatin1String( "\\\\" ), QLatin1String( "\\" ) );
return s;
}
QVariant
get(const QString& type)
{
return data[type.toUpper()];
}
QVariant
get(Type type)
{
switch(type){
case(Title):
return get(QLatin1String( "title" ));
case(Comment):
return get(QLatin1String( "comment" ));
case(Artist):
return get(QLatin1String( "artist" ));
case(Genre):
return get(QLatin1String( "genre" ));
case(Year):
return get(QLatin1String( "year" ));
case(Length):
return get(QLatin1String( "length" ));
case(Category):
return get(QLatin1String( "category" ));
}
return QVariant();
}
void
set(const QString& type, const QVariant &d)
{
//kDebug() << "set: " << type << ", " << d.toString();
if(type.contains(QRegExp( QLatin1String( "^T.*_.*$" )) )){
kDebug(60010) << "Error: custom cdinfo::set data can not start with T and contain a _";
return;
}
if(type.toUpper() == QLatin1String( "DTITLE" )){
kDebug(60010) << "Error: type: DTITLE is reserved and can not be set.";
return;
}
data[type.toUpper()] = d;
}
void
set(Type type, const QVariant &d)
{
switch(type)
{
case(Title):
set(QLatin1String( "title" ), d);
return;
case(Comment):
set(QLatin1String( "comment" ), d);
return;
case(Artist):
set(QLatin1String( "artist" ), d);
return;
case(Genre):
set(QLatin1String( "genre" ), d);
return;
case(Year):
set(QLatin1String( "year" ), d);
return;
case(Length):
set(QLatin1String( "length" ), d);
return;
case(Category):
set(QLatin1String( "category" ), d);
return;
}
Q_ASSERT(false);
}
// Appends text to data instead of overwriting it
void
append(const QString& type, const QString& text)
{
set(type, get(type).toString().append(text));
}
void
append(Type type, const QString& text)
{
set(type, get(type).toString().append(text));
}
QMap<QString, QVariant> data;
} ;
class TrackInfoPrivate : public InfoBasePrivate {
};
TrackInfo::TrackInfo()
{
d = new TrackInfoPrivate();
}
TrackInfo::TrackInfo(const TrackInfo& clone)
: d(new TrackInfoPrivate)
{
d->data = clone.d->data;
}
TrackInfo::~TrackInfo()
{
delete d;
}
TrackInfo& TrackInfo::operator=(const TrackInfo& clone)
{
d->data = clone.d->data;
return *this;
}
QVariant TrackInfo::get(Type type) const {
return d->get(type);
}
QVariant TrackInfo::get(const QString &type) const {
return d->get(type);
}
void TrackInfo::set(const QString &type, const QVariant &data){
d->set(type, data);
}
void TrackInfo::set(Type type, const QVariant &data) {
d->set(type, data);
}
void TrackInfo::clear(){
d->data.clear();
}
QString TrackInfo::toString() const {
QString out;
bool ok;
int track = get(QLatin1String( "tracknumber" )).toInt(&ok);
if(!ok)
kDebug(60010) << "Warning toString() on a track that doesn't have track number assigned.";
QMap<QString, QVariant>::const_iterator i = d->data.constBegin();
while (i != d->data.constEnd()) {
if(i.key() != QLatin1String( "COMMENT" ) && i.key() != QLatin1String( "TITLE" ) && i.key() != QLatin1String( "ARTIST" ) && i.key() != QLatin1String( "TRACKNUMBER" )) {
out += d->createLine(QString::fromLatin1("T%1_%2").arg(i.key()).arg(track),i.value().toString());
}
++i;
}
return out;
}
bool TrackInfo::operator==( const TrackInfo& other ) const
{
return d->data == other.d->data;
}
bool TrackInfo::operator!=( const TrackInfo& other ) const
{
return d->data != other.d->data;
}
class CDInfoPrivate : public InfoBasePrivate {
public:
TrackInfoList trackInfoList;
};
CDInfo::CDInfo()
: d(new CDInfoPrivate())
{
set(QLatin1String( "revision" ), 0);
}
CDInfo::CDInfo(const CDInfo& clone)
: d(new CDInfoPrivate())
{
d->data = clone.d->data;
d->trackInfoList = clone.d->trackInfoList;
}
CDInfo::~CDInfo()
{
delete d;
}
CDInfo& CDInfo::operator=(const CDInfo& clone)
{
d->trackInfoList = clone.d->trackInfoList;
d->data = clone.d->data;
return *this;
}
bool
CDInfo::load(const QString & string)
{
return load(string.split(QLatin1Char( '\n' ),QString::SkipEmptyParts));
}
bool
CDInfo::load(const QStringList & lineList)
{
clear();
// We'll append to this until we've seen all the lines, then parse it after.
QString dtitle;
QStringList::ConstIterator it = lineList.begin();
QRegExp rev(QLatin1String( "# Revision: (\\d+)" ));
QRegExp eol(QLatin1String( "[\r\n]" ));
while ( it != lineList.end() )
{
QString line(*it);
line.replace(eol,QLatin1String( "" ));
++it;
if (rev.indexIn(line) != -1)
{
set(QLatin1String( "revision" ), rev.cap(1).toUInt());
continue;
}
QStringList tokenList = KStringHandler::perlSplit(QLatin1Char( '=' ), line, 2);
if (2 != tokenList.count())
{
continue;
}
QString key = tokenList[0].trimmed();
QString value = d->unescape ( tokenList[1] );
if ( QLatin1String( "DTITLE" ) == key )
{
dtitle += value;
}
else if ( key.startsWith(QLatin1String( "TTITLE" )) )
{
uint trackNumber = key.mid(6).toUInt();
TrackInfo& ti = track(trackNumber);
ti.set(Title, ti.get(Title).toString().append(value));
}
else if ( QLatin1String( "EXTD" ) == key )
{
d->append(Comment, value);
}
else if ( QLatin1String( "DGENRE" ) == key )
{
d->append(Genre, value);
}
else if ( QLatin1String( "DYEAR" ) == key )
{
set(Year, value);
}
else if ( key.startsWith(QLatin1String( "EXTT" )) )
{
uint trackNumber = key.mid( 4 ).toUInt();
checkTrack( trackNumber );
QString extt = track(trackNumber).get(Comment).toString() + value;
track(trackNumber).set(Comment, extt);
}
else if ( key.startsWith(QLatin1String( "T" )) )
{
// Custom Track data
uint trackNumber = key.mid( key.indexOf(QLatin1Char( '_' ))+1 ).toUInt();
checkTrack( trackNumber );
QRegExp data(QString::fromLatin1("^T.*_%1$").arg(trackNumber));
if ( key.contains( data ) )
{
QString k = key.mid(1, key.indexOf(QLatin1Char( '_' ))-1);
TrackInfo& ti = track(trackNumber);
ti.set( k, ti.get(k).toString().append(value) );
}
}
else
{
// Custom Disk data
d->append( key, value );
}
}
int slashPos = dtitle.indexOf(QLatin1String( " / " ));
if (-1 == slashPos)
{
// Use string for title _and_ artist.
set(Artist, dtitle);
set(Title, dtitle);
}
else
{
set(Artist, dtitle.left(slashPos).trimmed());
set(Title, dtitle.mid(slashPos + 3).trimmed());
}
bool isSampler = true;
for (TrackInfoList::Iterator it = d->trackInfoList.begin(); it != d->trackInfoList.end(); ++it)
{
if (!(*it).get(Title).toString().contains(QLatin1String( " / " )))
{
isSampler = false;
}
}
for (TrackInfoList::Iterator it = d->trackInfoList.begin(); it != d->trackInfoList.end(); ++it)
{
if (isSampler)
{
int delimiter = (*it).get(Title).toString().indexOf(QLatin1String( " / " ));
(*it).set(Artist, (*it).get(Title).toString().left(delimiter));
(*it).set(Title, (*it).get(Title).toString().mid(delimiter + 3));
}
else
{
(*it).set(Artist, get(Artist));
}
}
if ( get(Genre).toString().isEmpty() )
set(Genre, QLatin1String( "Unknown" ));
kDebug(60010) << "Loaded CDInfo for " << get(QLatin1String( "discid" )).toString();
return true;
}
QString
CDInfo::toString(bool submit) const
{
QString s;
if (get(QLatin1String( "revision" )) != 0)
s += QLatin1String( "# Revision: " ) + get(QLatin1String( "revision" )).toString() + QLatin1Char( '\n' );
// If we are submiting make it a fully compliant CDDB entry
if (submit)
{
s += QLatin1String( "#\n" );
s += QString::fromLatin1("# Submitted via: %1 %2\n").arg(CDDB::clientName(),
CDDB::clientVersion());
}
s += d->createLine(QLatin1String( "DISCID" ), get(QLatin1String( "discid" )).toString() );
QString artist = get(Artist).toString();
s += d->createLine(QLatin1String( "DTITLE" ), artist + QLatin1String( " / " ) + get(Title).toString() );
int year = get(Year).toInt();
s += QLatin1String( "DYEAR=" ) + (0 == year ? QString::null : QString::number(year)) + QLatin1Char( '\n' ); //krazy:exclude=nullstrassign for old broken gcc
if (get(Genre) == QLatin1String( "Unknown" ))
s += d->createLine(QLatin1String( "DGENRE" ), QString());
else
s += d->createLine(QLatin1String( "DGENRE" ),get(Genre).toString());
bool isSampler = false;
for (int i = 0; i < d->trackInfoList.count(); ++i){
QString trackArtist = d->trackInfoList[i].get(Artist).toString();
if (!trackArtist.isEmpty() && trackArtist != artist)
{
isSampler = true;
break;
}
}
for (int i = 0; i < d->trackInfoList.count(); ++i){
QString trackTitle = d->trackInfoList[i].get(Title).toString();
QString trackArtist = d->trackInfoList[i].get(Artist).toString();
if (isSampler)
{
if (trackArtist.isEmpty())
s += d->createLine(QString::fromLatin1("TTITLE%1").arg(i), QString::fromLatin1("%1 / %2").arg(artist).arg(trackTitle));
else
s += d->createLine(QString::fromLatin1("TTITLE%1").arg(i), QString::fromLatin1("%1 / %2").arg(trackArtist).arg(trackTitle));
}
else
{
s += d->createLine(QString::fromLatin1("TTITLE%1").arg(i), trackTitle);
}
}
s += d->createLine(QLatin1String("EXTD"), get(Comment).toString());
for (int i = 0; i < d->trackInfoList.count(); ++i)
s += d->createLine(QString::fromLatin1("EXTT%1").arg(i), d->trackInfoList[i].get(Comment).toString());
if (submit)
{
s += d->createLine(QLatin1String( "PLAYORDER" ), QString());
return s;
}
s += d->createLine(QLatin1String( "PLAYORDER" ), get(QLatin1String( "playorder" )).toString() );
// Custom track data
for (int i = 0; i < d->trackInfoList.count(); ++i)
s += d->trackInfoList[i].toString();
QStringList cddbKeywords;
cddbKeywords
<< QLatin1String( "DISCID" )
<< QLatin1String( "ARTIST" )
<< QLatin1String( "TITLE" )
<< QLatin1String( "COMMENT" )
<< QLatin1String( "YEAR" )
<< QLatin1String( "GENRE" )
<< QLatin1String( "PLAYORDER" )
<< QLatin1String( "CATEGORY" )
<< QLatin1String( "REVISION" );
// Custom disc data
QMap<QString, QVariant>::const_iterator i = d->data.constBegin();
while (i != d->data.constEnd()){
if (!cddbKeywords.contains(i.key()) && i.key() != QLatin1String( "SOURCE" ))
{
s+= d->createLine(i.key(), i.value().toString());
}
++i;
}
return s;
}
QVariant CDInfo::get(Type type) const {
return d->get(type);
}
QVariant CDInfo::get(const QString &type) const {
return d->get(type);
}
void CDInfo::set(const QString &type, const QVariant &data){
d->set(type, data);
}
void CDInfo::set(Type type, const QVariant &data) {
d->set(type, data);
}
void
CDInfo::checkTrack( int trackNumber )
{
while ( d->trackInfoList.count() <= trackNumber ){
int count = d->trackInfoList.count();
d->trackInfoList.append(TrackInfo());
d->trackInfoList[count].set(QLatin1String( "tracknumber" ), count);
}
}
void
CDInfo::clear()
{
d->data.clear();
d->trackInfoList.clear();
}
bool
CDInfo::isValid() const
{
QString discid = get(QLatin1String( "DISCID" )).toString();
if (discid.isEmpty())
return false;
if (discid == QLatin1String( "0" ))
return false;
return true;
}
TrackInfo &
CDInfo::track( int trackNumber )
{
checkTrack( trackNumber );
return d->trackInfoList[trackNumber];
}
TrackInfo
CDInfo::track( int trackNumber ) const
{
if (trackNumber < d->trackInfoList.count())
return d->trackInfoList[trackNumber];
else
{
kWarning() << "Couldn't find track " << trackNumber;
return TrackInfo();
}
}
int
CDInfo::numberOfTracks() const
{
return d->trackInfoList.count();
}
bool CDInfo::operator==( const CDInfo& other ) const
{
return( d->data == other.d->data &&
d->trackInfoList == other.d->trackInfoList );
}
bool CDInfo::operator!=( const CDInfo& other ) const
{
return( d->data != other.d->data ||
d->trackInfoList != other.d->trackInfoList );
}
}
// vim:tabstop=2:shiftwidth=2:expandtab:cinoptions=(s,U1,m1

212
libkcddb/libkcddb/cdinfo.h Normal file
View file

@ -0,0 +1,212 @@
/*
Copyright (C) 2002 Rik Hemsley (rikkus) <rik@kde.org>
Copyright (C) 2002-2005 Benjamin Meyer <ben-devel@meyerhome.net>
Copyright (C) 2002-2004 Nadeem Hasan <nhasan@nadmm.com>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#ifndef KCDDB_CDINFO_H
#define KCDDB_CDINFO_H
#include <QtCore/QStringList>
#include <QtCore/QVariant>
#include <libkcddb/kcddb_export.h>
namespace KCDDB
{
/**
* The most common types
*/
enum Type
{
Title, /**< The title of the track or CD */
Comment, /**< A comment for the track or CD */
Artist, /**< The artist of the track or CD */
Genre, /**< The genre of the track or CD */
Year, /**< The year the cd or track was produced
By default, the year of the track is the
same as for the whole cd
@todo Doesn't do that for tracks right now.*/
Length, /**< The length of a track or a full CD
@todo In what unit? */
Category /**< The freedb category of the entry.
Needs to be one of: blues, classical,
country, data, fold, jazz, misc, newage,
reggae, rock, soundtrack */
};
/**
* Information about a sepecific track in a cd.
*/
class KCDDB_EXPORT TrackInfo
{
public:
TrackInfo();
virtual ~TrackInfo();
TrackInfo(const TrackInfo& clone);
TrackInfo& operator=(const TrackInfo& clone);
bool operator==(const TrackInfo&) const;
bool operator!=(const TrackInfo&) const;
/**
* Get data for type that has been assigned to this track.
* @p type is case insensitive.
* For example <code>get("title")</code>
*/
QVariant get(const QString &type) const;
/**
* Helper function that calls type with the common name
*/
QVariant get(Type type) const;
/**
* Set any data from this track.
* @p type is case insensitive.
* For example <code>set("title", "Rock this world")</code>
* Useful for atributes that other apps want to add.
* Data will be stored in the local cddb cache, but not sent to the cddb server
*/
void set(const QString &type, const QVariant &data);
/**
* Helper function that calls type with the common name
*/
void set(Type type, const QVariant &data);
/**
* @return a CDDB compatible string of all the data assigned to this track
* tracknumber must be assigned before calling this.
*/
QString toString() const;
/**
* internal
*/
void clear();
private:
class TrackInfoPrivate *d;
};
typedef QList<TrackInfo> TrackInfoList;
/**
* Information about a CD
*
* Typically CDInfo is obtained from the client such as:
* <code>KCDDB::Client *cddb = new KCDDB::Client();
* cddb->lookup(discSignature);
* CDInfo info = cddb->lookupResponse().first();</code>
*/
class KCDDB_EXPORT CDInfo
{
public:
CDInfo();
virtual ~CDInfo();
CDInfo(const CDInfo& clone);
CDInfo& operator=(const CDInfo& clone);
bool operator==(const CDInfo&) const;
bool operator!=(const CDInfo&) const;
/**
* Load CDInfo from a string that is CDDB compatible
* @return true if successful
*/
bool load(const QString &string);
/**
* Load CDInfo from a stringList that is CDDB compatible
* @return true if successful
*/
bool load(const QStringList &stringList);
/**
* Clear all information, setting this to invalid
* internal
*/
void clear();
/**
* @return true if the cd information is valid
*/
bool isValid() const;
/**
* @param submit If submit is true only returns CDDB compatible information
* @return a string containing all of the CD's information.
*/
QString toString(bool submit=false) const;
/**
* Get data for type that has been assigned to this disc.
* @p type is case insensitive.
* For example <code>get("title")</code>
*/
QVariant get(const QString &type) const;
/**
* Helper function that calls type with the common name
*/
QVariant get(Type type) const;
/**
* Set any data from this disc.
* @p type is case insensitive.
* For example <code>set("title", "Rock this world")</code>
* Useful for atributes that other apps want to add.
* Data will be stored in the local cddb cache, but not sent to the cddb server
*/
void set(const QString &type, const QVariant &data);
/**
* Helper function that calls type with the common name
*/
void set(Type type, const QVariant &data);
/**
* Returns track with nr @p trackNumber and adds it to
* the track list if it doesn't exist (first track is 0)
*/
TrackInfo & track( int trackNumber );
/**
* Returns a const track with nr @p trackNumber
* or a new if it doesn't exist (first track is 0)
*/
TrackInfo track( int trackNumber ) const;
/**
* Returns number of tracks on CD
*/
int numberOfTracks() const;
protected:
/**
* Checks to make sure that trackNumber exists
*/
void checkTrack( int trackNumber );
private:
class CDInfoPrivate * const d;
};
typedef QList<CDInfo> CDInfoList;
}
#endif // KCDDB_CDINFO_H
// vim:tabstop=2:shiftwidth=2:expandtab:cinoptions=(s,U1,m1

View file

@ -0,0 +1,312 @@
/*
Copyright (c) 2005 Shaheedur R. Haque <srhaque@iee.org>
Copyright (C) 2005 Richard Lärkäng <nouseforaname@home.se>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#include "cdinfodialog.h"
#include "cdinfoencodingwidget.h"
#include "ui_cdinfodialog.h"
#include <QTextCodec>
#include <QStringList>
#include <QStandardItemModel>
#include <kdebug.h>
#include <kglobal.h>
#include <kcharsets.h>
#include <klocale.h>
using KCDDB::TrackInfo;
namespace KCDDB
{
class CDInfoDialog::Private
{
public:
Private()
: ui(new Ui::CDInfoDialogBase)
{
}
CDInfo info;
KCDDB::Genres genres;
KCDDB::Categories categories;
Ui::CDInfoDialogBase* ui;
static QLatin1String SEPARATOR;
static const unsigned TRACK_NUMBER = 0;
static const unsigned TRACK_TIME = 1;
static const unsigned TRACK_TITLE = 2;
static const unsigned TRACK_ARTIST = 3;
static const unsigned TRACK_COMMENT = 4;
};
QLatin1String CDInfoDialog::Private::SEPARATOR = QLatin1String( " / " );
CDInfoDialog::CDInfoDialog(QWidget* parent)
: KDialog(parent),
d(new Private)
{
QWidget* w = new QWidget(this);
d->ui->setupUi(w);
setMainWidget(w);
d->info.set(QLatin1String( "source" ), QLatin1String( "user" ));
d->categories = KCDDB::Categories();
d->ui->m_category->addItems(d->categories.i18nList());
d->genres = KCDDB::Genres();
d->ui->m_genre->addItems(d->genres.i18nList());
m_trackModel = new QStandardItemModel(0, 5, this);
d->ui->m_trackList->setModel(m_trackModel);
// We want control over the visibility of this column. See artistChanged().
// d->ui->m_trackList->setColumnWidthMode(Private::TRACK_ARTIST, Q3ListView::Manual);
// ensure we get our translations
KGlobal::locale()->insertCatalog( QLatin1String( "libkcddb" ));
connect( d->ui->m_trackList, SIGNAL(activated(QModelIndex)), this, SLOT(slotTrackSelected(QModelIndex)) );
connect( d->ui->m_trackList, SIGNAL(doubleClicked(QModelIndex)), this, SLOT(slotTrackDoubleClicked(QModelIndex)) );
connect( d->ui->m_artist, SIGNAL(textChanged(QString)), this, SLOT(artistChanged(QString)) );
connect( d->ui->m_genre, SIGNAL(textChanged(QString)), this, SLOT(genreChanged(QString)) );
connect( d->ui->m_multiple, SIGNAL(toggled(bool)), this, SLOT(slotMultipleArtists(bool)) );
connect(d->ui->m_changeEncoding,SIGNAL(clicked()),SLOT(slotChangeEncoding()));
}
void CDInfoDialog::slotTrackSelected( const QModelIndex &index )
{
emit play(index.data().toUInt()-1);
}
CDInfoDialog::~CDInfoDialog()
{
delete d->ui;
delete d;
}
void CDInfoDialog::slotNextTrack()
{
/* QTreeWidgetItem *item = d->ui->m_trackList->itemBelow(d->ui->m_trackList->currentItem());
if (item)
{
d->ui->m_trackList->setCurrentItem(item);*/
// d->ui->m_trackList->ensureItemVisible(item);
// }
}
void CDInfoDialog::slotTrackDoubleClicked(const QModelIndex &index)
{
// d->ui->m_trackList->editItem(item);
}
void CDInfoDialog::setInfo( const KCDDB::CDInfo &info, const KCDDB::TrackOffsetList &trackStartFrames )
{
d->info = info;
d->ui->m_artist->setText(info.get(Artist).toString().trimmed());
d->ui->m_title->setText(info.get(Title).toString().trimmed());
d->ui->m_category->setItemText(d->ui->m_category->currentIndex(), d->categories.cddb2i18n(info.get(Category).toString()));
// Make sure the revision is set before the genre to allow the genreChanged() handler to fire.
d->ui->m_revision->setText(QString::number(info.get(QLatin1String( "revision" )).toInt()));
d->ui->m_genre->setItemText(d->ui->m_genre->currentIndex(), d->genres.cddb2i18n(info.get(Genre).toString()));
d->ui->m_year->setValue(info.get(Year).toInt());
d->ui->m_comment->setText(info.get(Comment).toString().trimmed());
d->ui->m_id->setText(info.get(QLatin1String( "discid" )).toString().trimmed());
// Now do the individual tracks.
unsigned tracks = info.numberOfTracks();
if (tracks > 0)
{
d->ui->m_length->setText(framesTime(trackStartFrames[tracks] - trackStartFrames[0]));
}
m_trackModel->clear();
QStringList labels;
labels << i18n("Track") << i18n("Length") << i18n("Title") << i18n("Artist") << i18n("Comment");
m_trackModel->setHorizontalHeaderLabels(labels);
for (unsigned i = 0; i < tracks; i++) {
QList<QStandardItem *> trackItems = QList<QStandardItem *>();
TrackInfo ti(info.track(i));
QStandardItem *trackNumberItem = new QStandardItem(QString().sprintf("%02d", i + 1));
trackNumberItem->setEditable(FALSE);
trackItems << trackNumberItem;
QStandardItem *trackLengthItem = new QStandardItem(framesTime(trackStartFrames[i + 1] - trackStartFrames[i]));
trackLengthItem->setEditable(FALSE);
trackItems << trackLengthItem;
QStandardItem *trackTitleItem = new QStandardItem(ti.get(Title).toString());
trackItems << trackTitleItem;
QStandardItem *trackArtistItem = new QStandardItem(ti.get(Artist).toString());
trackItems << trackArtistItem;
QStandardItem *trackCommentItem = new QStandardItem(ti.get(Comment).toString());
trackItems << trackCommentItem;
m_trackModel->appendRow(trackItems);
}
// FIXME KDE4: handle playorder here too, once KCDDBInfo::CDInfo is updated.
if (info.get(Artist).toString() == QLatin1String( "Various" ) || d->ui->m_multiple->isChecked()){
d->ui->m_trackList->resizeColumnToContents(Private::TRACK_ARTIST);
}
}
QString CDInfoDialog::framesTime(unsigned frames)
{
QTime time;
double ms;
ms = frames * 1000 / 75.0;
time = time.addMSecs((int)ms);
// Use ".zzz" for milliseconds...
QString temp2;
if (time.hour() > 0)
temp2 = time.toString(QLatin1String( "hh:mm:ss" ));
else
temp2 = time.toString(QLatin1String( "mm:ss" ));
return temp2;
} // framesTime
KCDDB::CDInfo CDInfoDialog::info() const
{
KCDDB::CDInfo info = d->info;
info.set(Artist, d->ui->m_artist->text().trimmed());
info.set(Title, d->ui->m_title->text().trimmed());
info.set(Category, d->categories.i18n2cddb(d->ui->m_category->currentText()));
info.set(Genre, d->genres.i18n2cddb(d->ui->m_genre->currentText()));
info.set(Year, d->ui->m_year->value());
info.set(Comment, d->ui->m_comment->text().trimmed());
info.set(QLatin1String( "revision" ), d->ui->m_revision->text().trimmed().toUInt());
info.set(QLatin1String( "discid" ), d->ui->m_id->text().trimmed());
for (int t = 0; t < m_trackModel->rowCount(); ++t) {
TrackInfo& track = info.track(t);
track.set(Artist, m_trackModel->index(t, Private::TRACK_ARTIST).data().toString().trimmed());
track.set(Title, m_trackModel->index(t, Private::TRACK_TITLE).data().toString().trimmed());
track.set(Comment, m_trackModel->index(t, Private::TRACK_COMMENT).data().toString().trimmed());
// FIXME KDE4: handle track lengths here too, once KCDDBInfo::CDInfo is updated.
}
// FIXME KDE4: handle playorder here too, once KCDDBInfo::CDInfo is updated.
return info;
}
void CDInfoDialog::artistChanged( const QString &newArtist )
{
// Enable special handling of compilations.
if (newArtist.trimmed().compare(QLatin1String( "Various" ))) {
d->ui->m_multiple->setChecked(false);
} else {
d->ui->m_multiple->setChecked(true);
}
}
void CDInfoDialog::genreChanged( const QString &newGenre )
{
// Disable changes to category if the version number indicates that a record
// is already in the database, or if the genre is poorly set. The latter
// condition also provides a "back-door" override.
d->ui->m_category->setEnabled((d->ui->m_revision->text().trimmed().toUInt() < 1) ||
(newGenre.compare(QLatin1String( "Unknown" )) == 0));
}
void CDInfoDialog::slotMultipleArtists( bool hasMultipleArtist)
{
if (hasMultipleArtist) {
for (int t = 0; t < m_trackModel->rowCount(); ++t) {
QString title = m_trackModel->index(t, Private::TRACK_TITLE).data().toString();
int separator = title.indexOf(Private::SEPARATOR);
if (separator != -1) {
// Artists probably entered already
m_trackModel->setData(m_trackModel->index(t, Private::TRACK_ARTIST), title.left(separator));
m_trackModel->setData(m_trackModel->index(t, Private::TRACK_TITLE), title.mid(separator + 3));
}
}
d->ui->m_trackList->resizeColumnToContents(Private::TRACK_ARTIST);
d->ui->m_trackList->resizeColumnToContents(Private::TRACK_TITLE);
} else {
for (int t = 0; t < m_trackModel->rowCount(); ++t) {
QString artist = m_trackModel->index(t, Private::TRACK_ARTIST).data().toString();
if (!artist.isEmpty()) {
m_trackModel->setData(m_trackModel->index(t, Private::TRACK_ARTIST), QString());
QString title = m_trackModel->index(t, Private::TRACK_TITLE).data().toString();
artist += Private::SEPARATOR + title;
m_trackModel->setData(m_trackModel->index(t, Private::TRACK_TITLE), artist);
}
}
d->ui->m_trackList->hideColumn(Private::TRACK_ARTIST);
d->ui->m_trackList->resizeColumnToContents(Private::TRACK_TITLE);
}
}
void CDInfoDialog::slotChangeEncoding()
{
KDialog* dialog = new KDialog(this);
dialog->setCaption(i18n("Change Encoding"));
dialog->setButtons( KDialog::Ok | KDialog::Cancel);
dialog->setModal( true );
QStringList songTitles;
for (int t = 0; t < m_trackModel->rowCount(); ++t) {
QString title = m_trackModel->index(t, Private::TRACK_ARTIST).data().toString().trimmed();
if (!title.isEmpty())
title.append(Private::SEPARATOR);
title.append(m_trackModel->index(t, Private::TRACK_TITLE).data().toString().trimmed());
songTitles << title;
}
KCDDB::CDInfoEncodingWidget* encWidget = new KCDDB::CDInfoEncodingWidget(
dialog, d->ui->m_artist->text(),d->ui->m_title->text(), songTitles);
dialog->setMainWidget(encWidget);
if (dialog->exec())
{
KCharsets* charsets = KGlobal::charsets();
QTextCodec* codec = charsets->codecForName(charsets->encodingForName(encWidget->selectedEncoding()));
d->ui->m_artist->setText(codec->toUnicode(d->ui->m_artist->text().toLatin1()));
d->ui->m_title->setText(codec->toUnicode(d->ui->m_title->text().toLatin1()));
d->ui->m_genre->setItemText(d->ui->m_genre->currentIndex(), codec->toUnicode(d->ui->m_genre->currentText().toLatin1()));
d->ui->m_comment->setText(codec->toUnicode(d->ui->m_comment->text().toLatin1()));
QModelIndex trackIndex = m_trackModel->index(0, 0, QModelIndex());
int trackRows = m_trackModel->rowCount(trackIndex);
for (int t = 0; t < trackRows; ++t) {
QString artist = m_trackModel->index(t, Private::TRACK_ARTIST, trackIndex).data().toString();
m_trackModel->setData(m_trackModel->index(t, Private::TRACK_ARTIST, trackIndex), codec->toUnicode(artist.toLatin1()));
QString title = m_trackModel->index(t, Private::TRACK_TITLE, trackIndex).data().toString();
m_trackModel->setData(m_trackModel->index(t, Private::TRACK_TITLE, trackIndex), codec->toUnicode(title.toLatin1()));
QString comment = m_trackModel->index(t, Private::TRACK_COMMENT, trackIndex).data().toString();
m_trackModel->setData(m_trackModel->index(t, Private::TRACK_COMMENT, trackIndex), codec->toUnicode(comment.toLatin1()));
}
}
}
}
#include "moc_cdinfodialog.cpp"

View file

@ -0,0 +1,65 @@
/*
Copyright (C) 2005 Richard Lärkäng <nouseforaname@home.se>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#ifndef KCDDB_CDINFODIALOG_H
#define KCDDB_CDINFODIALOG_H
#include <libkcddb/kcddb_export.h>
#include <libkcddb/cdinfo.h>
#include <libkcddb/kcddb.h>
#include <KDE/KDialog>
class QStandardItemModel;
class QModelIndex;
namespace KCDDB
{
class KCDDB_EXPORT CDInfoDialog : public KDialog
{
Q_OBJECT
public:
explicit CDInfoDialog(QWidget* parent);
virtual ~CDInfoDialog();
void setInfo( const KCDDB::CDInfo &info, const KCDDB::TrackOffsetList &trackStartFrames );
KCDDB::CDInfo info() const;
Q_SIGNALS:
void play( int );
private Q_SLOTS:
void slotTrackSelected( const QModelIndex &index );
void slotNextTrack();
void slotTrackDoubleClicked(const QModelIndex &index);
void artistChanged( const QString &newArtist );
void genreChanged( const QString &newGenre );
void slotMultipleArtists( bool hasMultipleArtist );
void slotChangeEncoding();
private:
QString framesTime(unsigned frames);
QStandardItemModel *m_trackModel;
class Private;
Private * const d;
} ;
}
#endif // KCDDB_CDINFODIALOG_H

View file

@ -0,0 +1,283 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>CDInfoDialogBase</class>
<widget class="QWidget" name="CDInfoDialogBase">
<property name="enabled">
<bool>true</bool>
</property>
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>501</width>
<height>600</height>
</rect>
</property>
<layout class="QVBoxLayout">
<property name="spacing">
<number>6</number>
</property>
<property name="margin">
<number>10</number>
</property>
<item>
<layout class="QGridLayout">
<property name="margin">
<number>0</number>
</property>
<property name="spacing">
<number>6</number>
</property>
<item row="5" column="2">
<widget class="QLabel" name="lb_revision">
<property name="text">
<string>Revision:</string>
</property>
</widget>
</item>
<item row="1" column="1" colspan="3">
<widget class="KLineEdit" name="m_title">
<property name="toolTip">
<string>Use the name of the artist if there is no title.</string>
</property>
</widget>
</item>
<item row="4" column="0">
<widget class="QLabel" name="lb_category">
<property name="text">
<string>&amp;Category:</string>
</property>
<property name="buddy">
<cstring>m_category</cstring>
</property>
</widget>
</item>
<item row="5" column="1">
<widget class="QLabel" name="m_id">
<property name="text">
<string/>
</property>
</widget>
</item>
<item row="0" column="1" colspan="3">
<widget class="KLineEdit" name="m_artist">
<property name="toolTip">
<string>Write names as &quot;first last&quot;, not &quot;last, first&quot;. Omit any leading &quot;The&quot;. Use &quot;Various&quot; for compilations.</string>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QLabel" name="lb_artist">
<property name="text">
<string>&amp;Artist:</string>
</property>
<property name="buddy">
<cstring>m_artist</cstring>
</property>
</widget>
</item>
<item row="3" column="0">
<widget class="QLabel" name="lb_year">
<property name="text">
<string>&amp;Year:</string>
</property>
<property name="buddy">
<cstring>m_year</cstring>
</property>
</widget>
</item>
<item row="4" column="2">
<widget class="QLabel" name="lb_genre">
<property name="text">
<string>&amp;Genre:</string>
</property>
<property name="buddy">
<cstring>m_genre</cstring>
</property>
</widget>
</item>
<item row="4" column="1">
<widget class="KComboBox" name="m_category">
<property name="enabled">
<bool>false</bool>
</property>
<property name="toolTip">
<string>Disc Id values must be unique within a category.</string>
</property>
</widget>
</item>
<item row="3" column="1">
<widget class="KIntSpinBox" name="m_year">
<property name="maximum">
<number>2100</number>
</property>
</widget>
</item>
<item row="6" column="0" colspan="2">
<widget class="QCheckBox" name="m_multiple">
<property name="text">
<string>&amp;Multiple artists</string>
</property>
</widget>
</item>
<item row="2" column="1" colspan="3">
<widget class="KLineEdit" name="m_comment"/>
</item>
<item row="2" column="0">
<widget class="QLabel" name="lb_comment">
<property name="text">
<string>Comment:</string>
</property>
<property name="buddy">
<cstring>m_comment</cstring>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="lb_title">
<property name="text">
<string>&amp;Title:</string>
</property>
<property name="buddy">
<cstring>m_title</cstring>
</property>
</widget>
</item>
<item row="4" column="3">
<widget class="KComboBox" name="m_genre">
<property name="toolTip">
<string>Avoid custom values, as they will be written to CDDB as-is.</string>
</property>
<property name="editable">
<bool>true</bool>
</property>
<property name="duplicatesEnabled">
<bool>false</bool>
</property>
</widget>
</item>
<item row="5" column="0">
<widget class="QLabel" name="lb_id">
<property name="text">
<string>Disc Id:</string>
</property>
</widget>
</item>
<item row="3" column="2">
<widget class="QLabel" name="lb_length">
<property name="text">
<string>Length:</string>
</property>
</widget>
</item>
<item row="5" column="3">
<widget class="QLabel" name="m_revision"/>
</item>
<item row="3" column="3">
<widget class="QLabel" name="m_length">
<property name="text">
<string/>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QTreeView" name="m_trackList">
<property name="toolTip">
<string>For a CD-Extra, set title to &quot;Data&quot;.</string>
</property>
<property name="rootIsDecorated">
<bool>false</bool>
</property>
<property name="itemsExpandable">
<bool>false</bool>
</property>
<property name="allColumnsShowFocus">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout">
<property name="spacing">
<number>6</number>
</property>
<property name="margin">
<number>0</number>
</property>
<item>
<spacer>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Expanding</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>231</width>
<height>41</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QPushButton" name="m_changeEncoding">
<property name="text">
<string>Change Encoding...</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QLabel" name="lb_playingOrder">
<property name="text">
<string>Playing order:</string>
</property>
</widget>
</item>
<item>
<widget class="KLineEdit" name="m_playOrder"/>
</item>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>KComboBox</class>
<extends>QComboBox</extends>
<header>kcombobox.h</header>
</customwidget>
<customwidget>
<class>KLineEdit</class>
<extends>QLineEdit</extends>
<header>klineedit.h</header>
<container>1</container>
</customwidget>
<customwidget>
<class>KIntSpinBox</class>
<extends>QSpinBox</extends>
<header>knuminput.h</header>
<container>1</container>
</customwidget>
</customwidgets>
<tabstops>
<tabstop>m_artist</tabstop>
<tabstop>m_title</tabstop>
<tabstop>m_comment</tabstop>
<tabstop>m_year</tabstop>
<tabstop>m_category</tabstop>
<tabstop>m_genre</tabstop>
<tabstop>m_trackList</tabstop>
<tabstop>m_playOrder</tabstop>
</tabstops>
<includes>
<include location="local">libkcddb/cdinfo.h</include>
<include location="local">libkcddb/kcddb.h</include>
<include location="local">libkcddb/categories.h</include>
<include location="local">libkcddb/genres.h</include>
</includes>
<resources/>
<connections/>
</ui>

View file

@ -0,0 +1,70 @@
/*
Copyright (C) 2005 Richard Lärkäng <nouseforaname@home.se>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#include "cdinfoencodingwidget.h"
#include <qtextcodec.h>
#include <klocale.h>
#include <kglobal.h>
#include <kcharsets.h>
namespace KCDDB
{
CDInfoEncodingWidget::CDInfoEncodingWidget(QWidget* parent, const QString& artist,
const QString& title, const QStringList& songTitles)
: QWidget(parent), CDInfoEncodingWidgetBase(), m_artist(artist), m_title(title),
m_songTitles(songTitles)
{
setupUi(this);
encodingCombo->addItems(KGlobal::charsets()->descriptiveEncodingNames());
slotEncodingChanged(encodingCombo->currentText());
connect(encodingCombo,SIGNAL(activated(QString)),
this,SLOT(slotEncodingChanged(QString)));
}
QString CDInfoEncodingWidget::selectedEncoding()
{
return encodingCombo->currentText();
}
void CDInfoEncodingWidget::slotEncodingChanged(const QString& encoding)
{
KCharsets* charsets = KGlobal::charsets();
QTextCodec* codec = charsets->codecForName(charsets->encodingForName(encoding));
songsBox->clear();
QStringList newTitles;
for (QStringList::const_iterator it = m_songTitles.constBegin();
it != m_songTitles.constEnd(); ++it)
newTitles << codec->toUnicode((*it).toLatin1().constData());
songsBox->clear();
songsBox->addItems(newTitles);
titleLabel->setText(i18nc("artist - cdtitle", "%1 - %2",
codec->toUnicode(m_artist.toLatin1()), codec->toUnicode(m_title.toLatin1().constData())));
}
}
#include "moc_cdinfoencodingwidget.cpp"

View file

@ -0,0 +1,46 @@
/*
Copyright (C) 2005 Richard Lärkäng <nouseforaname@home.se>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#ifndef KCDDB_CDINFOENCODINGWIDGET_H
#define KCDDB_CDINFOENCODINGWIDGET_H
#include "ui_cdinfoencodingwidget.h"
namespace KCDDB
{
class CDInfoEncodingWidget : public QWidget, private Ui::CDInfoEncodingWidgetBase
{
Q_OBJECT
public:
CDInfoEncodingWidget(QWidget* parent, const QString& artist, const QString& title,
const QStringList& songTitles);
virtual ~CDInfoEncodingWidget() { }
QString selectedEncoding();
private slots:
void slotEncodingChanged(const QString &);
private:
QString m_artist, m_title;
QStringList m_songTitles;
} ;
}
#endif // KCDDB_CDINFOENCODINGWIDGET_H

View file

@ -0,0 +1,73 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>CDInfoEncodingWidgetBase</class>
<widget class="QWidget" name="CDInfoEncodingWidgetBase">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>350</width>
<height>372</height>
</rect>
</property>
<layout class="QGridLayout">
<property name="margin">
<number>10</number>
</property>
<property name="spacing">
<number>6</number>
</property>
<item row="0" column="0">
<widget class="QLabel" name="encodingLabel">
<property name="text">
<string>Encoding</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QComboBox" name="encodingCombo"/>
</item>
<item row="1" column="0" colspan="2">
<widget class="QGroupBox" name="groupBox1">
<property name="title">
<string>Preview</string>
</property>
<layout class="QVBoxLayout">
<property name="spacing">
<number>6</number>
</property>
<property name="margin">
<number>10</number>
</property>
<item>
<widget class="QLabel" name="titleLabel">
<property name="text">
<string/>
</property>
</widget>
</item>
<item>
<widget class="KListWidget" name="songsBox">
<property name="minimumSize">
<size>
<width>300</width>
<height>250</height>
</size>
</property>
</widget>
</item>
</layout>
</widget>
</item>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>KListWidget</class>
<extends>QListWidget</extends>
<header>klistwidget.h</header>
</customwidget>
</customwidgets>
<resources/>
<connections/>
</ui>

View file

@ -0,0 +1,376 @@
/*
Copyright (C) 2002 Rik Hemsley (rikkus) <rik@kde.org>
Copyright (C) 2002-2005 Benjamin C. Meyer <ben at meyerhome dot net>
Copyright (C) 2003 Richard Lärkäng <nouseforaname@home.se>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#include "client.h"
#include "synccddbplookup.h"
#include "asynccddbplookup.h"
#include "synchttplookup.h"
#include "asynchttplookup.h"
#include "syncsmtpsubmit.h"
#include "asyncsmtpsubmit.h"
#include "synchttpsubmit.h"
#include "asynchttpsubmit.h"
#include "cache.h"
#include "lookup.h"
#include "config-musicbrainz.h"
#ifdef HAVE_MUSICBRAINZ5
#include "musicbrainz/musicbrainzlookup.h"
#include "musicbrainz/asyncmusicbrainzlookup.h"
#endif
#include <kdebug.h>
namespace KCDDB
{
class Client::Private
{
public:
Private()
: cdInfoLookup(0),
cdInfoSubmit(0),
block( true )
{}
~Private()
{
delete cdInfoLookup;
delete cdInfoSubmit;
}
Lookup * cdInfoLookup;
Submit * cdInfoSubmit;
Config config;
CDInfoList cdInfoList;
TrackOffsetList trackOffsetList;
QList<Lookup *> pendingLookups;
bool block;
};
Client::Client()
: d(new Private)
{
d->config.readConfig();
}
Client::~Client()
{
delete d;
}
Config &
Client::config() const
{
return d->config;
}
void
Client::setBlockingMode( bool enable )
{
d->block = enable;
}
bool
Client::blockingMode() const
{
return d->block;
}
CDInfoList
Client::lookupResponse() const
{
return d->cdInfoList;
}
Result
Client::lookup(const TrackOffsetList & trackOffsetList)
{
d->cdInfoList.clear();
d->trackOffsetList = trackOffsetList;
if ( trackOffsetList.count() <= 1 )
{
kDebug(60010) << "Lookup called with empty offset list";
return NoRecordFound;
}
if ( d->config.cacheLookupEnabled() )
{
d->cdInfoList = Cache::lookup( trackOffsetList, config() );
kDebug(60010) << "Found " << d->cdInfoList.count() << " hit(s)";
if ( !d->cdInfoList.isEmpty() )
{
if ( !blockingMode() )
emit finished( Success );
return Success;
}
}
Result r = NoRecordFound;
// just in case we have an info lookup hanging around, prevent mem leakage
delete d->cdInfoLookup;
d->cdInfoLookup = 0;
if ( blockingMode() )
{
#ifdef HAVE_MUSICBRAINZ5
if ( d->config.musicBrainzLookupEnabled() )
{
d->cdInfoLookup = new MusicBrainzLookup();
r = d->cdInfoLookup->lookup( d->config.hostname(),
d->config.port(), trackOffsetList );
if ( Success == r )
{
d->cdInfoList = d->cdInfoLookup->lookupResponse();
Cache::store( d->trackOffsetList, d->cdInfoList, config() );
return r;
}
delete d->cdInfoLookup;
d->cdInfoLookup = 0L;
}
#endif
if ( d->config.freedbLookupEnabled() )
{
Lookup::Transport t = ( Lookup::Transport )d->config.freedbLookupTransport();
if( Lookup::CDDBP == t )
d->cdInfoLookup = new SyncCDDBPLookup();
else
d->cdInfoLookup = new SyncHTTPLookup();
r = d->cdInfoLookup->lookup( d->config.hostname(),
d->config.port(), trackOffsetList );
if ( Success == r )
{
d->cdInfoList = d->cdInfoLookup->lookupResponse();
Cache::store( d->trackOffsetList, d->cdInfoList, config() );
return r;
}
delete d->cdInfoLookup;
d->cdInfoLookup = 0L;
}
return r;
}
else
{
#ifdef HAVE_MUSICBRAINZ5
if ( d->config.musicBrainzLookupEnabled() )
{
AsyncMusicBrainzLookup* lookup = new AsyncMusicBrainzLookup();
connect( lookup, SIGNAL(finished(KCDDB::Result)),
SLOT(slotFinished(KCDDB::Result)) );
d->pendingLookups.append( lookup );
}
#endif
if ( d->config.freedbLookupEnabled() )
{
Lookup::Transport t = ( Lookup::Transport )d->config.freedbLookupTransport();
if( Lookup::CDDBP == t )
{
AsyncCDDBPLookup* lookup = new AsyncCDDBPLookup();
connect( lookup, SIGNAL(finished(KCDDB::Result)),
SLOT(slotFinished(KCDDB::Result)) );
d->pendingLookups.append( lookup );
}
else
{
AsyncHTTPLookup* lookup = new AsyncHTTPLookup();
connect( lookup, SIGNAL(finished(KCDDB::Result)),
SLOT(slotFinished(KCDDB::Result)) );
d->pendingLookups.append( lookup );
}
}
return runPendingLookups();
}
}
void
Client::slotFinished( Result r )
{
if ( d->cdInfoLookup && Success == r )
{
d->cdInfoList = d->cdInfoLookup->lookupResponse();
Cache::store( d->trackOffsetList, d->cdInfoList, config() );
}
else
d->cdInfoList.clear();
if ( d->cdInfoLookup ) // in case someone called lookup() while finished() was being processed, and deleted cdInfoLookup.
{
d->cdInfoLookup->deleteLater();
d->cdInfoLookup = 0L;
}
if ( Success == r )
{
emit finished( r );
qDeleteAll( d->pendingLookups );
d->pendingLookups.clear();
}
else
{
runPendingLookups();
}
}
void
Client::slotSubmitFinished( Result r )
{
emit finished( r );
d->cdInfoSubmit->deleteLater();
d->cdInfoSubmit=0L;
}
Result
Client::submit(const CDInfo &cdInfo, const TrackOffsetList& offsetList)
{
// Check if it's valid
if (!cdInfo.isValid())
return CannotSave;
uint last=0;
for (int i=0; i < offsetList.count(); i++)
{
if(last >= offsetList[i])
return CannotSave;
last = offsetList[i];
}
//TODO Check that it is edited
// just in case we have a cdInfoSubmit, prevent memory leakage
delete d->cdInfoSubmit;
QString from = d->config.emailAddress();
switch (d->config.freedbSubmitTransport())
{
case Submit::HTTP:
{
QString hostname = d->config.httpSubmitServer();
uint port = d->config.httpSubmitPort();
if ( blockingMode() )
d->cdInfoSubmit = new SyncHTTPSubmit(from, hostname, port);
else
{
d->cdInfoSubmit = new AsyncHTTPSubmit(from, hostname, port);
connect( static_cast<AsyncHTTPSubmit *>( d->cdInfoSubmit ),
SIGNAL(finished(KCDDB::Result)),
SLOT(slotSubmitFinished(KCDDB::Result)) );
}
break;
}
case Submit::SMTP:
{
QString hostname = d->config.smtpHostname();
uint port = d->config.smtpPort();
QString username = d->config.smtpUsername();
if ( blockingMode() )
d->cdInfoSubmit = new SyncSMTPSubmit( hostname, port, username, from, d->config.submitAddress() );
else
{
d->cdInfoSubmit = new AsyncSMTPSubmit( hostname, port, username, from, d->config.submitAddress() );
connect( static_cast<AsyncSMTPSubmit *>( d->cdInfoSubmit ),
SIGNAL(finished(KCDDB::Result)),
SLOT(slotSubmitFinished(KCDDB::Result)) );
}
break;
}
default:
kDebug(60010) << "Unsupported transport: ";
// << CDDB::transportToString(d->config.submitTransport()) << endl;
return UnknownError;
break;
}
Result r = d->cdInfoSubmit->submit( cdInfo, offsetList );
if ( blockingMode() )
{
delete d->cdInfoSubmit;
d->cdInfoSubmit = 0L;
}
return r;
}
Result
Client::runPendingLookups()
{
if (!d->pendingLookups.empty())
{
d->cdInfoLookup = d->pendingLookups.takeFirst();
Result r = d->cdInfoLookup->lookup( d->config.hostname(),
d->config.port(), d->trackOffsetList );
if ( Success != r )
{
delete d->cdInfoLookup;
d->cdInfoLookup = 0L;
}
return r;
}
else
{
emit finished( NoRecordFound );
return NoRecordFound;
}
}
void
Client::store(const CDInfo &cdInfo, const TrackOffsetList& offsetList)
{
Cache::store(offsetList, cdInfo, config());
}
}
#include "moc_client.cpp"
// vim:tabstop=2:shiftwidth=2:expandtab:cinoptions=(s,U1,m1

111
libkcddb/libkcddb/client.h Normal file
View file

@ -0,0 +1,111 @@
/*
Copyright (C) 2002 Rik Hemsley (rikkus) <rik@kde.org>
Copyright (C) 2002-2005 Benjamin C. Meyer <ben at meyerhome dot net>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#ifndef KCDDB_CLIENT_H
#define KCDDB_CLIENT_H
#include "kcddbconfig.h"
#include "cdinfo.h"
#include <QtCore/QObject>
#include "kcddb.h"
#include <kdemacros.h>
namespace KCDDB
{
class Lookup;
class Submit;
/**
* Class used to obtain CDDB information about a CD
*
* Example:
* <code>KCDDB::Client *cddb = new KCDDB::Client();
* cddb->lookup(discSignature);
* CDInfo info = cddb->lookupResponse().first();</code>
*/
class KCDDB_EXPORT Client : public QObject
{
Q_OBJECT
public:
/**
* Uses settings read from config.
*/
Client();
virtual ~Client();
Config & config() const;
/**
* @return a list of CDDB entries that match the disc signature
*/
CDInfoList lookupResponse() const;
/**
* Searches the database for entries matching the offset list.
* Use lookupResponse() to get the results
*
* @param trackOffsetList A List of the start offsets of the tracks,
* and the offset of the lead-out track at the end of the list
*
* @return if the results of the lookup: Success, NoRecordFound, etc
*/
Result lookup(const TrackOffsetList &trackOffsetList);
/**
* @returns the results of trying to submit
*/
Result submit(const CDInfo &cdInfo, const TrackOffsetList &trackOffsetList);
/**
* Stores the CD-information in the local cache
*/
void store(const CDInfo &cdInfo, const TrackOffsetList &trackOffsetList);
void setBlockingMode( bool );
bool blockingMode() const;
Q_SIGNALS:
/**
* emitted when not blocking and lookup() finished.
*/
void finished( KCDDB::Result result );
protected Q_SLOTS:
/**
* Called when the lookup is finished with the result
*/
void slotFinished( KCDDB::Result result );
/**
* Called when the submit is finished with the result
*/
void slotSubmitFinished( KCDDB::Result result );
private:
Result runPendingLookups();
class Private;
Private * const d;
};
}
#endif // KCDDB_CLIENT_H
// vim:tabstop=2:shiftwidth=2:expandtab:cinoptions=(s,U1,m1

View file

@ -0,0 +1,6 @@
ClassName=ConfigBase
File=libkcddb.kcfg
Mutators=true
IncludeFiles=libkcddb/kcddb_export.h
Visibility=KCDDB_EXPORT
MemberVariables=dpointer

View file

@ -0,0 +1,159 @@
// Copyright (C) 2005 by Shaheed Haque (srhaque@iee.org). All rights reserved.
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
#include "genres.h"
#include <klocale.h>
class KCDDB::Genres::Private
{
public:
QStringList cddb;
QStringList i18n;
};
KCDDB::Genres::Genres()
: d(new Private)
{
// The Genre is completely arbitrary. But we follow kaudiocreator's cue
// and make life easy for people.
//
// To cope with preexisting records which don't match an entry, we will
// add one later if needed.
d->cddb << QLatin1String( "Unknown" ) << QLatin1String( "A Cappella" ) << QLatin1String( "Acid Jazz" ) <<
QLatin1String( "Acid Punk" ) << QLatin1String( "Acid" ) << QLatin1String( "Acoustic" ) << QLatin1String( "Alternative" ) <<
QLatin1String( "Alt. Rock" ) << QLatin1String( "Ambient" ) << QLatin1String( "Anime" ) << QLatin1String( "Avantgarde" ) <<
QLatin1String( "Ballad" ) << QLatin1String( "Bass" ) << QLatin1String( "Beat" ) << QLatin1String( "Bebop" ) <<
QLatin1String( "Big Band" ) << QLatin1String( "Black Metal" ) << QLatin1String( "Bluegrass" ) << QLatin1String( "Blues" ) <<
QLatin1String( "Booty Bass" ) << QLatin1String( "BritPop" ) << QLatin1String( "Cabaret" ) << QLatin1String( "Celtic" ) <<
QLatin1String( "Chamber Music" ) << QLatin1String( "Chanson" ) << QLatin1String( "Chorus" ) << QLatin1String( "Christian Gangsta Rap" ) <<
QLatin1String( "Christian Rap" ) << QLatin1String( "Christian Rock" ) << QLatin1String( "Classical" ) << QLatin1String( "Classic Rock" ) <<
QLatin1String( "Club-house" ) << QLatin1String( "Club" ) << QLatin1String( "Comedy" ) << QLatin1String( "Contemporary Christian" ) <<
QLatin1String( "Country" ) << QLatin1String( "Crossover" ) << QLatin1String( "Cult" ) << QLatin1String( "Dance Hall" ) <<
QLatin1String( "Dance" ) << QLatin1String( "Darkwave" ) << QLatin1String( "Death Metal" ) << QLatin1String( "Disco" ) <<
QLatin1String( "Dream" ) << QLatin1String( "Drum & Bass" ) << QLatin1String( "Drum Solo" ) << QLatin1String( "Duet" ) <<
QLatin1String( "Easy Listening" ) << QLatin1String( "Electronic" ) << QLatin1String( "Ethnic" ) << QLatin1String( "Eurodance" ) <<
QLatin1String( "Euro-House" ) << QLatin1String( "Euro-Techno" ) << QLatin1String( "Fast-Fusion" ) << QLatin1String( "Folklore" ) <<
QLatin1String( "Folk/Rock" ) << QLatin1String( "Folk" ) << QLatin1String( "Freestyle" ) << QLatin1String( "Funk" ) <<
QLatin1String( "Fusion" ) << QLatin1String( "Game" ) << QLatin1String( "Gangsta Rap" ) << QLatin1String( "Goa" ) <<
QLatin1String( "Gospel" ) << QLatin1String( "Gothic Rock" ) << QLatin1String( "Gothic" ) << QLatin1String( "Grunge" ) <<
QLatin1String( "Hardcore" ) << QLatin1String( "Hard Rock" ) << QLatin1String( "Heavy Metal" ) << QLatin1String( "Hip-Hop" ) <<
QLatin1String( "House" ) << QLatin1String( "Humor" ) << QLatin1String( "Indie" ) << QLatin1String( "Industrial" ) <<
QLatin1String( "Instrumental Pop" ) << QLatin1String( "Instrumental Rock" ) << QLatin1String( "Instrumental" ) << QLatin1String( "Jazz+Funk" ) <<
QLatin1String( "Jazz" ) << QLatin1String( "JPop" ) << QLatin1String( "Jungle" ) << QLatin1String( "Latin" ) << QLatin1String( "Lo-Fi" ) <<
QLatin1String( "Meditative" ) << QLatin1String( "Merengue" ) << QLatin1String( "Metal" ) << QLatin1String( "Musical" ) <<
QLatin1String( "National Folk" ) << QLatin1String( "Native American" ) << QLatin1String( "Negerpunk" ) << QLatin1String( "New Age" ) <<
QLatin1String( "New Wave" ) << QLatin1String( "Noise" ) << QLatin1String( "Oldies" ) << QLatin1String( "Opera" ) <<
QLatin1String( "Other" ) << QLatin1String( "Polka" ) << QLatin1String( "Polsk Punk" ) << QLatin1String( "Pop-Funk" ) <<
QLatin1String( "Pop/Funk" ) << QLatin1String( "Pop" ) << QLatin1String( "Porn Groove" ) << QLatin1String( "Power Ballad" ) <<
QLatin1String( "Pranks" ) << QLatin1String( "Primus" ) << QLatin1String( "Progressive Rock" ) << QLatin1String( "Psychedelic Rock" ) <<
QLatin1String( "Psychedelic" )<< QLatin1String( "Punk Rock" ) << QLatin1String( "Punk" ) << QLatin1String( "R&B" ) <<
QLatin1String( "Rap" ) << QLatin1String( "Rave" ) << QLatin1String( "Reggae" ) << QLatin1String( "Retro" ) <<
QLatin1String( "Revival" ) << QLatin1String( "Rhythmic Soul" ) << QLatin1String( "Rock & Roll" ) << QLatin1String( "Rock" ) <<
QLatin1String( "Salsa" ) << QLatin1String( "Samba" ) << QLatin1String( "Satire" ) << QLatin1String( "Showtunes" ) <<
QLatin1String( "Ska" ) << QLatin1String( "Slow Jam" ) << QLatin1String( "Slow Rock" ) << QLatin1String( "Sonata" ) <<
QLatin1String( "Soul" ) << QLatin1String( "Sound Clip" ) << QLatin1String( "Soundtrack" ) << QLatin1String( "Southern Rock" ) <<
QLatin1String( "Space" ) << QLatin1String( "Speech" ) << QLatin1String( "Swing" ) << QLatin1String( "Symphonic Rock" ) <<
QLatin1String( "Symphony" ) << QLatin1String( "Synthpop" ) << QLatin1String( "Tango" ) << QLatin1String( "Techno-Industrial" ) <<
QLatin1String( "Techno" ) << QLatin1String( "Terror" ) << QLatin1String( "Thrash Metal" ) << QLatin1String( "Top 40" ) <<
QLatin1String( "Trailer" ) << QLatin1String( "Trance" ) << QLatin1String( "Tribal" ) << QLatin1String( "Trip-Hop" ) <<
QLatin1String( "Vocal" );
d->i18n << i18n("Unknown") << i18n("A Cappella") << i18n("Acid Jazz") <<
i18n("Acid Punk") << i18n("Acid") << i18n("Acoustic") << i18n("Alternative") <<
i18n("Alt. Rock") << i18n("Ambient") << i18n("Anime") << i18n("Avantgarde") <<
i18n("Ballad") << i18n("Bass") << i18n("Beat") << i18n("Bebop") <<
i18n("Big Band") << i18n("Black Metal") << i18n("Bluegrass") << i18n("Blues") <<
i18n("Booty Bass") << i18n("BritPop") << i18n("Cabaret") << i18n("Celtic") <<
i18n("Chamber Music") << i18n("Chanson") << i18n("Chorus") << i18n("Christian Gangsta Rap") <<
i18n("Christian Rap") << i18n("Christian Rock") << i18n("Classical") << i18n("Classic Rock") <<
i18n("Club-house") << i18n("Club") << i18n("Comedy") << i18n("Contemporary Christian") <<
i18nc("music genre", "Country") << i18n("Crossover") << i18n("Cult") << i18n("Dance Hall") <<
i18n("Dance") << i18n("Darkwave") << i18n("Death Metal") << i18n("Disco") <<
i18n("Dream") << i18n("Drum & Bass") << i18n("Drum Solo") << i18n("Duet") <<
i18n("Easy Listening") << i18n("Electronic") << i18n("Ethnic") << i18n("Eurodance") <<
i18n("Euro-House") << i18n("Euro-Techno") << i18n("Fast-Fusion") << i18n("Folklore") <<
i18n("Folk/Rock") << i18n("Folk") << i18n("Freestyle") << i18n("Funk") <<
i18n("Fusion") << i18n("Game") << i18n("Gangsta Rap") << i18n("Goa") <<
i18n("Gospel") << i18n("Gothic Rock") << i18n("Gothic") << i18n("Grunge") <<
i18n("Hardcore") << i18n("Hard Rock") << i18n("Heavy Metal") << i18n("Hip-Hop") <<
i18n("House") << i18n("Humor") << i18n("Indie") << i18n("Industrial") <<
i18n("Instrumental Pop") << i18n("Instrumental Rock") << i18n("Instrumental") << i18n("Jazz+Funk") <<
i18n("Jazz") << i18n("JPop") << i18n("Jungle") << i18n("Latin") << i18n("Lo-Fi") <<
i18n("Meditative") << i18n("Merengue") << i18n("Metal") << i18n("Musical") <<
i18n("National Folk") << i18n("Native American") << i18n("Negerpunk") << i18n("New Age") <<
i18n("New Wave") << i18n("Noise") << i18n("Oldies") << i18n("Opera") <<
i18n("Other") << i18n("Polka") << i18n("Polsk Punk") << i18n("Pop-Funk") <<
i18n("Pop/Funk") << i18n("Pop") << i18n("Porn Groove") << i18n("Power Ballad") <<
i18n("Pranks") << i18n("Primus") << i18n("Progressive Rock") << i18n("Psychedelic Rock") <<
i18n("Psychedelic") << i18n("Punk Rock") << i18n("Punk") << i18n("R&B") <<
i18n("Rap") << i18n("Rave") << i18n("Reggae") << i18n("Retro") <<
i18n("Revival") << i18n("Rhythmic Soul") << i18n("Rock & Roll") << i18n("Rock") <<
i18n("Salsa") << i18n("Samba") << i18n("Satire") << i18n("Showtunes") <<
i18n("Ska") << i18n("Slow Jam") << i18n("Slow Rock") << i18n("Sonata") <<
i18n("Soul") << i18n("Sound Clip") << i18n("Soundtrack") << i18n("Southern Rock") <<
i18n("Space") << i18n("Speech") << i18n("Swing") << i18n("Symphonic Rock") <<
i18n("Symphony") << i18n("Synthpop") << i18n("Tango") << i18n("Techno-Industrial") <<
i18n("Techno") << i18n("Terror") << i18n("Thrash Metal") << i18n("Top 40") <<
i18n("Trailer") << i18n("Trance") << i18n("Tribal") << i18n("Trip-Hop") <<
i18n("Vocal");
}
KCDDB::Genres::~Genres()
{
delete d;
}
KCDDB::Genres::Genres(const Genres& other)
:d(new Private)
{
*d = *other.d;
}
KCDDB::Genres& KCDDB::Genres::operator=(const Genres& other)
{
*d = *other.d;
return *this;
}
const QStringList &KCDDB::Genres::cddbList() const
{
return d->cddb;
}
const QStringList &KCDDB::Genres::i18nList() const
{
return d->i18n;
}
const QString KCDDB::Genres::cddb2i18n(const QString &genre) const
{
QString userDefinedGenre = genre.trimmed();
int index = d->cddb.indexOf(userDefinedGenre);
if (index != -1)
{
return d->i18n[index];
}
else
{
return userDefinedGenre;
}
}
const QString KCDDB::Genres::i18n2cddb(const QString &genre) const
{
QString userDefinedGenre = genre.trimmed();
int index = d->i18n.indexOf(userDefinedGenre);
if (index != -1)
{
return d->cddb[index];
}
else
{
return userDefinedGenre;
}
}

View file

@ -0,0 +1,47 @@
// Copyright (C) 2005 by Shaheed Haque (srhaque@iee.org). All rights reserved.
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
#ifndef KCDDB_GENRES_H
#define KCDDB_GENRES_H
#include <QtCore/QStringList>
#include <libkcddb/kcddb_export.h>
namespace KCDDB
{
/**
* The Genre is completely arbitrary. But we follow kaudiocreator's cue
* and make life easy for people.
*/
class KCDDB_EXPORT Genres
{
public:
Genres();
Genres(const Genres&);
~Genres();
Genres& operator=(const Genres&);
const QStringList &cddbList() const;
const QStringList &i18nList() const;
/**
* Lookup the CDDB genre, and return the i18n'd version.
*/
const QString cddb2i18n(const QString &genre) const;
/**
* Lookup the i18n genre, and return the CDDB version if we can.
*/
const QString i18n2cddb(const QString &genre) const;
private:
class Private;
Private * const d;
};
}
#endif

View file

@ -0,0 +1,188 @@
/*
Copyright ( C ) 2002 Rik Hemsley ( rikkus ) <rik@kde.org>
Copyright ( C ) 2002 Benjamin Meyer <ben-devel@meyerhome.net>
Copyright ( C ) 2002 Nadeem Hasan <nhasan@kde.org>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or ( at your option ) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#include "httplookup.h"
#include <kio/job.h>
#include <kdebug.h>
namespace KCDDB
{
HTTPLookup::HTTPLookup()
: Lookup(),
block_( true ), state_( Idle ), result_( Success )
{
}
HTTPLookup::~HTTPLookup()
{
}
Result
HTTPLookup::sendQuery()
{
QString cmd = QString::fromLatin1( "cddb query %1 %2" )
.arg( trackOffsetListToId(), trackOffsetListToString() ) ;
makeURL( cmd );
Result result = fetchURL();
return result;
}
Result
HTTPLookup::sendRead( const CDDBMatch & match )
{
category_ = match.first;
discid_ = match.second;
QString cmd = QString::fromLatin1( "cddb read %1 %2" )
.arg( category_, discid_ );
makeURL( cmd );
Result result = fetchURL();
return result;
}
void
HTTPLookup::initURL( const QString & hostName, uint port )
{
cgiURL_.setProtocol( QLatin1String( "http" ) );
cgiURL_.setHost( hostName );
cgiURL_.setPort( port );
cgiURL_.setPath( QLatin1String( "/~cddb/cddb.cgi" ) );
return;
}
void
HTTPLookup::makeURL( const QString & cmd )
{
// The whole query has to constructed each time as the
// CDDB CGI script expects the parameters in strict order
cgiURL_.setQuery( QString::null ); //krazy:exclude=nullstrassign for old broken gcc
QString hello = QString::fromLatin1("%1 %2 %3 %4")
.arg(user_, localHostName_, clientName(), clientVersion());
cgiURL_.addQueryItem( QLatin1String( "cmd" ), cmd );
cgiURL_.addQueryItem( QLatin1String( "hello" ), hello );
cgiURL_.addQueryItem( QLatin1String( "proto" ), QLatin1String( "6" ) );
}
void
HTTPLookup::jobFinished()
{
QStringList lineList = QString::fromUtf8(data_, data_.size()).split( QLatin1String( "\n" ), QString::SkipEmptyParts );
QStringList::ConstIterator it = lineList.constBegin();
switch ( state_ )
{
case WaitingForQueryResponse:
if ( it != lineList.constEnd() )
{
QString line( *it );
result_ = parseQuery( line );
switch ( result_ )
{
case Success:
if ( !block_ )
emit queryReady();
break;
case MultipleRecordFound:
++it;
while ( it != lineList.constEnd() )
{
QString line( *it );
if ( QLatin1Char( '.' ) == line[ 0 ] )
{
result_ = Success;
if ( !block_ )
emit queryReady();
break;
}
parseExtraMatch( line );
++it;
}
break;
case ServerError:
case NoRecordFound:
if ( !block_ )
emit queryReady();
return;
break;
default:
break;
}
}
break;
case WaitingForReadResponse:
{
CDInfo info;
if ( info.load( QString::fromUtf8(data_,data_.size()) ) )
{
info.set( QLatin1String( "category" ), category_ );
info.set( QLatin1String( "discid" ), discid_ );
info.set( QLatin1String( "source" ), QLatin1String( "freedb" ) );
cdInfoList_.append( info );
}
if ( !block_ )
emit readReady();
}
return;
break;
default:
break;
}
result_ = Success;
}
}
#include "moc_httplookup.cpp"
// vim:tabstop=2:shiftwidth=2:expandtab:cinoptions=(s,U1,m1

View file

@ -0,0 +1,81 @@
/*
Copyright (C) 2002 Rik Hemsley ( rikkus ) <rik@kde.org>
Copyright (C) 2002 Benjamin Meyer <ben-devel@meyerhome.net>
Copyright (C) 2002 Nadeem Hasan <nhasan@kde.org>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or ( at your option ) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#ifndef KCDDB_HTTP_LOOKUP_H
#define KCDDB_HTTP_LOOKUP_H
#include <kurl.h>
#include "lookup.h"
namespace KIO
{
class Job;
}
namespace KCDDB
{
class HTTPLookup : public Lookup
{
Q_OBJECT
public:
enum State
{
Idle,
WaitingForQueryResponse,
WaitingForReadResponse
};
HTTPLookup();
virtual ~HTTPLookup();
protected:
void initURL( const QString &, uint );
void makeURL( const QString & );
virtual Result fetchURL() = 0;
void jobFinished();
Result sendQuery();
Result sendRead( const CDDBMatch & );
signals:
void queryReady();
void readReady();
protected:
bool block_;
KUrl cgiURL_;
QByteArray data_;
State state_;
Result result_;
};
}
#endif
// vim:tabstop=2:shiftwidth=2:expandtab:cinoptions=(s,U1,m1

View file

@ -0,0 +1,62 @@
/*
Copyright (C) 2002 Benjamin Meyer <ben-devel@meyerhome.net>
Copyright (C) 2003 Richard Lärkäng <nouseforaname@home.se>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#include "httpsubmit.h"
#include <kdebug.h>
#include <kio/job.h>
namespace KCDDB
{
HTTPSubmit::HTTPSubmit(const QString& from, const QString& hostname, uint port)
: Submit(), from_(from)
{
url_.setProtocol( QLatin1String( "http" ));
url_.setHost(hostname);
url_.setPort(port);
url_.setPath(QLatin1String( "/~cddb/submit.cgi" ));
}
HTTPSubmit::~HTTPSubmit()
{
}
KIO::Job* HTTPSubmit::createJob(const CDInfo& cdInfo)
{
KIO::TransferJob* job = KIO::http_post(url_, diskData_.toUtf8().data(), KIO::HideProgressInfo);
job->addMetaData(QLatin1String( "content-type" ), QLatin1String( "Content-Type: text/plain" ));
QString header;
header += QLatin1String( "Content-Type: text/plain\n" );
header += QLatin1String( "Category: " ) + cdInfo.get(Category).toString() + QLatin1Char( '\n' );
header += QLatin1String( "Discid: " ) + cdInfo.get(QLatin1String( "discid" )).toString() + QLatin1Char( '\n' );
header += QLatin1String( "User-Email: " ) + from_ + QLatin1Char( '\n' );
//header += QLatin1String( "Submit-Mode: test\n" );
header += QLatin1String( "Submit-Mode: submit\n" );
header += QLatin1String( "Charset: UTF-8" );
job->addMetaData(QLatin1String( "customHTTPHeader" ), header);
return job;
}
}

View file

@ -0,0 +1,41 @@
#ifndef HTTPSUBMIT_H
#define HTTPSUBMIT_H
/*
Copyright (C) 2003 Richard Lärkäng <nouseforaname@home.se>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#include "submit.h"
#include <kurl.h>
namespace KCDDB
{
class HTTPSubmit : public Submit
{
public:
HTTPSubmit(const QString& from, const QString& hostname, uint port);
virtual ~HTTPSubmit();
protected:
virtual KIO::Job* createJob(const CDInfo& cdInfo);
KUrl url_;
QString from_;
} ;
}
#endif // HTTPSUBMIT_H

View file

@ -0,0 +1,68 @@
/*
Copyright (C) 2007 Richard Lärkäng <nouseforaname@home.se>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#include "kcddb.h"
#include <klocale.h>
namespace KCDDB
{
QString
resultToString(Result r)
{
switch (r)
{
case Success:
return i18n("Success");
break;
case ServerError:
return i18n("Server error");
break;
case HostNotFound:
return i18n("Host not found");
break;
case NoResponse:
return i18n("No response");
break;
case NoRecordFound:
return i18n("No record found");
break;
case MultipleRecordFound:
return i18n("Multiple records found");
break;
case CannotSave:
return i18n("Cannot save");
break;
case InvalidCategory:
return i18n("Invalid category");
break;
default:
return i18n("Unknown error");
break;
}
}
}

53
libkcddb/libkcddb/kcddb.h Normal file
View file

@ -0,0 +1,53 @@
/*
Copyright (C) 2007 Richard Lärkäng <nouseforaname@home.se>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#ifndef KCDDB_H
#define KCDDB_H
#include <QtCore/QList>
#include <QtCore/QString>
#include <libkcddb/kcddb_export.h>
namespace KCDDB
{
/** This list is used to calculate the CDDB disc id.
Insert the start frames ((minute*60 + seconds)*75+frames)
of all tracks, followed by the last frame of the disc. The
last frame is the start frame of the leadout track.
*/
typedef QList<uint> TrackOffsetList;
enum Result
{
Success,
ServerError,
HostNotFound,
NoResponse,
NoRecordFound,
MultipleRecordFound,
CannotSave,
InvalidCategory,
UnknownError
};
KCDDB_EXPORT QString resultToString(Result);
}
#endif

View file

@ -0,0 +1,40 @@
/* This file is part of the KDE project
Copyright (C) 2007 David Faure <faure@kde.org>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#ifndef KCDDB_EXPORT_H
#define KCDDB_EXPORT_H
/* needed for KDE_EXPORT and KDE_IMPORT macros */
#include <kdemacros.h>
#ifndef KCDDB_EXPORT
# if defined(MAKE_KCDDB_LIB)
/* We are building this library */
# define KCDDB_EXPORT KDE_EXPORT
# else
/* We are using this library */
# define KCDDB_EXPORT KDE_IMPORT
# endif
#endif
# ifndef KCDDB_EXPORT_DEPRECATED
# define KCDDB_EXPORT_DEPRECATED KDE_DEPRECATED KCDDB_EXPORT
# endif
#endif

View file

@ -0,0 +1,56 @@
/*
Copyright (C) 2002 Rik Hemsley (rikkus) <rik@kde.org>
Copyright (C) 2002 Benjamin Meyer <ben-devel@meyerhome.net>
Copyright (C) 2002 Nadeem Hasan <nhasan@kde.org>
Copyright (C) 2003 Richard Lärkäng <nouseforaname@home.se>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#include <libkcddb/kcddbconfig.h>
#include <kemailsettings.h>
namespace KCDDB
{
Config::Config()
: ConfigBase()
{
loadEmailSettings();
}
void Config::loadEmailSettings()
{
KEMailSettings kes;
kes.setProfile( kes.defaultProfileName() );
static_cast<KConfigSkeleton::ItemString *>(findItem(QLatin1String( "emailAddress" )))
->setDefaultValue(kes.getSetting( KEMailSettings::EmailAddress ));
static_cast<KConfigSkeleton::ItemString *>(findItem(QLatin1String( "replyTo" )))
->setDefaultValue(kes.getSetting( KEMailSettings::ReplyToAddress ));
static_cast<KConfigSkeleton::ItemString *>(findItem(QLatin1String( "smtpHostname" )))
->setDefaultValue(kes.getSetting( KEMailSettings::OutServer ));
}
void Config::reparse()
{
loadEmailSettings();
readConfig();
}
}
// vim:tabstop=2:shiftwidth=2:expandtab:cinoptions=(s,U1,m1

View file

@ -0,0 +1,43 @@
/*
Copyright (C) 2002 Rik Hemsley (rikkus) <rik@kde.org>
Copyright (C) 2002 Benjamin Meyer <ben-devel@meyerhome.net>
Copyright (C) 2002 Nadeem Hasan <nhasan@kde.org>
Copyright (C) 2003 Richard Lärkäng <nouseforaname@home.se>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#ifndef KCDDB_CONFIG_H
#define KCDDB_CONFIG_H
#include <libkcddb/kcddb_export.h>
#include "configbase.h"
namespace KCDDB
{
class KCDDB_EXPORT Config : public ConfigBase
{
public:
Config();
void reparse();
private:
void loadEmailSettings();
};
}
#endif // KCDDB_CONFIG_H
// vim:tabstop=2:shiftwidth=2:expandtab:cinoptions=(s,U1,m1

View file

@ -0,0 +1,67 @@
<?xml version="1.0" encoding="UTF-8"?>
<kcfg xmlns="http://www.kde.org/standards/kcfg/1.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.kde.org/standards/kcfg/1.0
http://www.kde.org/standards/kcfg/1.0/kcfg.xsd" >
<include>QtCore/QDir</include>
<kcfgfile name="kcmcddbrc"/>
<group name="Lookup">
<entry name="hostname" type="String">
<default>freedb.freedb.org</default>
</entry>
<entry name="port" type="Int">
<default>80</default>
</entry>
<entry name="MusicBrainzLookupEnabled" type="Bool">
<default>true</default>
</entry>
<entry name="FreedbLookupEnabled" type="Bool">
<default>true</default>
</entry>
<entry name="CacheLookupEnabled" type="Bool">
<default>true</default>
</entry>
<entry name="FreedbLookupTransport" type="Enum">
<choices>
<choice name="CDDBP"></choice>
<choice name="HTTP"></choice>
</choices>
<default>HTTP</default>
</entry>
<entry name="cacheLocations" type="PathList">
<default code="true">QStringList(QDir::homePath()+QLatin1String("/.cddb/"))</default>
</entry>
</group>
<group name="Submit">
<entry name="FreedbSubmitTransport" type="Enum">
<choices>
<choice name="HTTP"></choice>
<choice name="SMTP"></choice>
</choices>
<default>HTTP</default>
</entry>
<entry name="emailAddress" type="String">
</entry>
<entry name="httpSubmitServer" type="String">
<default>freedb.freedb.org</default>
</entry>
<entry name="httpSubmitPort" type="Int">
<default>80</default>
</entry>
<entry name="smtpPort" type="Int">
<default>25</default>
</entry>
<entry name="smtpUsername" type="String">
</entry>
<entry name="useGlobalEmail" type="Bool">
<default>true</default>
</entry>
<entry name="replyTo" type="String">
</entry>
<entry name="smtpHostname" type="String">
</entry>
<entry name="submitAddress" type="String">
<default>freedb-submit@freedb.org</default>
</entry>
</group>
</kcfg>

View file

@ -0,0 +1,87 @@
/*
Copyright (C) 2002 Rik Hemsley (rikkus) <rik@kde.org>
Copyright (C) 2002 Benjamin Meyer <ben-devel@meyerhome.net>
CopyRight (C) 2002 Nadeem Hasan <nhasan@kde.org>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#include "lookup.h"
#include <kdebug.h>
namespace KCDDB
{
Lookup::Lookup()
: CDDB()
{
}
Lookup::~Lookup()
{
// Empty.
}
Result
Lookup::parseQuery( const QString & line )
{
uint serverStatus = statusCode( line );
if ( 200 == serverStatus )
{
QStringList tokenList = line.split( QLatin1Char( ' ' ), QString::SkipEmptyParts );
matchList_.append( qMakePair( tokenList[ 1 ], tokenList[ 2 ] ) );
return Success;
}
else if ( ( 211 == serverStatus ) || ( 210 == serverStatus ) )
{
return MultipleRecordFound;
}
else if ( 202 == serverStatus )
{
return NoRecordFound;
}
return ServerError;
}
void
Lookup::parseExtraMatch( const QString & line )
{
QStringList tokenList = line.split( QLatin1Char( ' ' ), QString::SkipEmptyParts );
matchList_.append( qMakePair( tokenList[ 0 ], tokenList[ 1 ] ) );
}
Result
Lookup::parseRead( const QString & line )
{
uint serverStatus = statusCode( line );
if ( 210 != serverStatus )
return ServerError;
return Success;
}
CDInfoList
Lookup::lookupResponse() const
{
return cdInfoList_;
}
}
// vim:tabstop=2:shiftwidth=2:expandtab:cinoptions=(s,U1,m1

View file

@ -0,0 +1,68 @@
/*
Copyright (C) 2002 Rik Hemsley (rikkus) <rik@kde.org>
Copyright (C) 2002 Benjamin Meyer <ben-devel@meyerhome.net>
CopyRight (C) 2002 Nadeem Hasan <nhasan@kde.org>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#ifndef KCDDB_LOOKUP_H
#define KCDDB_LOOKUP_H
#include <QtCore/QList>
#include <QtCore/QObject>
#include <QtCore/QPair>
#include <libkcddb/cddb.h>
#include <libkcddb/cdinfo.h>
namespace KCDDB
{
typedef QPair<QString, QString> CDDBMatch;
typedef QList<CDDBMatch> CDDBMatchList;
class Lookup : public CDDB, public QObject
{
public:
enum Transport
{
CDDBP,
HTTP
};
Lookup();
virtual ~Lookup();
virtual Result lookup( const QString &, uint, const TrackOffsetList & ) = 0;
CDInfoList lookupResponse() const;
protected:
void parseExtraMatch( const QString & );
Result parseQuery( const QString & );
Result parseRead( const QString & );
CDInfoList cdInfoList_;
CDDBMatchList matchList_;
QString category_;
QString discid_;
};
}
#endif // KCDDB_LOOKUP_H
// vim:tabstop=2:shiftwidth=2:expandtab:cinoptions=(s,U1,m1

View file

@ -0,0 +1,81 @@
/*
Copyright (C) 2006 Richard Lärkäng <nouseforaname@home.se>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#include "asyncmusicbrainzlookup.h"
#include "musicbrainzlookup.h"
#include <QtCore/QThread>
#include <kdebug.h>
namespace KCDDB
{
class LookupThread : public QThread
{
public:
void run()
{
MusicBrainzLookup lookup;
m_result = lookup.lookup(QString(), 0, m_offsetList);
if (m_result == Success)
m_lookupResponse = lookup.lookupResponse();
}
TrackOffsetList m_offsetList;
Result m_result;
CDInfoList m_lookupResponse;
} ;
AsyncMusicBrainzLookup::AsyncMusicBrainzLookup()
{
}
AsyncMusicBrainzLookup::~AsyncMusicBrainzLookup()
{
delete m_lookupThread;
}
Result AsyncMusicBrainzLookup::lookup( const QString &, uint, const TrackOffsetList & trackOffsetList )
{
m_lookupThread = new LookupThread();
m_lookupThread->m_offsetList = trackOffsetList;
connect(m_lookupThread, SIGNAL(finished()), SLOT(lookupFinished()));
m_lookupThread->start();
return Success;
}
void AsyncMusicBrainzLookup::lookupFinished()
{
kDebug() ;
cdInfoList_ = m_lookupThread->m_lookupResponse;
emit finished(m_lookupThread->m_result);
}
}
// vim:tabstop=2:shiftwidth=2:expandtab:cinoptions=(s,U1,m1
#include "moc_asyncmusicbrainzlookup.cpp"

View file

@ -0,0 +1,57 @@
/*
Copyright (C) 2006 Richard Lärkäng <nouseforaname@home.se>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#ifndef ASYNCMUSICBRAINZLOOKUP_H
#define ASYNCMUSICBRAINZLOOKUP_H
#include "lookup.h"
namespace KCDDB
{
class LookupThread;
class AsyncMusicBrainzLookup : public Lookup
{
Q_OBJECT
public:
AsyncMusicBrainzLookup();
virtual ~AsyncMusicBrainzLookup();
Result lookup( const QString &, uint, const TrackOffsetList & );
CDInfoList lookupResponse() const;
signals:
void finished( KCDDB::Result );
protected slots:
void lookupFinished( );
private:
LookupThread* m_lookupThread;
};
}
#endif // ASYNCMUSICBRAINZLOOKUP_H
// vim:tabstop=2:shiftwidth=2:expandtab:cinoptions=(s,U1,m1

View file

@ -0,0 +1,362 @@
/*
Copyright (C) 2005-2007 Richard Lärkäng <nouseforaname@home.se>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#include "musicbrainzlookup.h"
#include <kdebug.h>
#include <kcodecs.h>
#include <klocale.h>
#include <qcryptographichash.h>
#include <cstdio>
#include <cstring>
#include <musicbrainz5/Query.h>
#include <musicbrainz5/Medium.h>
#include <musicbrainz5/Release.h>
#include <musicbrainz5/ReleaseGroup.h>
#include <musicbrainz5/Track.h>
#include <musicbrainz5/Recording.h>
#include <musicbrainz5/Disc.h>
#include <musicbrainz5/HTTPFetch.h>
#include <musicbrainz5/ArtistCredit.h>
#include <musicbrainz5/Artist.h>
#include <musicbrainz5/NameCredit.h>
#include <musicbrainz5/SecondaryType.h>
namespace KCDDB
{
MusicBrainzLookup::MusicBrainzLookup()
{
}
MusicBrainzLookup::~MusicBrainzLookup()
{
}
Result MusicBrainzLookup::lookup( const QString &, uint, const TrackOffsetList & trackOffsetList )
{
QString discId = calculateDiscId(trackOffsetList);
kDebug() << "Should lookup " << discId;
MusicBrainz5::CQuery Query("libkcddb-0.5");
// Code adapted from libmusicbrainz/examples/cdlookup.cc
try {
MusicBrainz5::CMetadata Metadata=Query.Query("discid",discId.toAscii().constData());
if (Metadata.Disc() && Metadata.Disc()->ReleaseList())
{
MusicBrainz5::CReleaseList *ReleaseList=Metadata.Disc()->ReleaseList();
kDebug() << "Found " << ReleaseList->NumItems() << " release(s)";
int relnr=1;
for (int i = 0; i < ReleaseList->NumItems(); i++)
{
MusicBrainz5::CRelease* Release=ReleaseList->Item(i);
//The releases returned from LookupDiscID don't contain full information
MusicBrainz5::CQuery::tParamMap Params;
Params["inc"]="artists labels recordings release-groups url-rels discids artist-credits";
std::string ReleaseID=Release->ID();
MusicBrainz5::CMetadata Metadata2=Query.Query("release",ReleaseID,"",Params);
if (Metadata2.Release())
{
MusicBrainz5::CRelease *FullRelease=Metadata2.Release();
//However, these releases will include information for all media in the release
//So we need to filter out the only the media we want.
MusicBrainz5::CMediumList MediaList=FullRelease->MediaMatchingDiscID(discId.toAscii().constData());
if (MediaList.NumItems() > 0)
{
/*if (FullRelease->ReleaseGroup())
kDebug() << "Release group title: " << FullRelease->ReleaseGroup()->Title();
else
kDebug() << "No release group for this release";*/
kDebug() << "Found " << MediaList.NumItems() << " media item(s)";
for (int i=0; i < MediaList.NumItems(); i++)
{
MusicBrainz5::CMedium* Medium= MediaList.Item(i);
/*kDebug() << "Found media: '" << Medium.Title() << "', position " << Medium.Position();*/
CDInfo info;
info.set(QLatin1String( "source" ), QLatin1String( "musicbrainz" ));
// Uses musicbrainz discid for the first release,
// then discid-2, discid-3 and so on, to
// allow multiple releases with the same discid
if (relnr == 1)
info.set(QLatin1String( "discid" ), discId);
else
info.set(QLatin1String( "discid" ), discId+QLatin1String( "-" )+QString::number(relnr));
QString title = QString::fromUtf8(FullRelease->Title().c_str());
if (FullRelease->MediumList()->NumItems() > 1)
title = i18n("%1 (disc %2)", title, Medium->Position());
info.set(Title, title);
info.set(Artist, artistFromCreditList(FullRelease->ArtistCredit()));
QString date = QString::fromUtf8(FullRelease->Date().c_str());
QRegExp yearRe("^(\\d{4,4})(-\\d{1,2}-\\d{1,2})?$");
int year = 0;
if (yearRe.indexIn(date) > -1)
{
QString yearString = yearRe.cap(1);
bool ok;
year=yearString.toInt(&ok);
if (!ok)
year = 0;
}
info.set(Year, year);
MusicBrainz5::CTrackList *TrackList=Medium->TrackList();
if (TrackList)
{
for (int i=0; i < TrackList->NumItems(); i++)
{
MusicBrainz5::CTrack* Track=TrackList->Item(i);
MusicBrainz5::CRecording *Recording=Track->Recording();
TrackInfo& track = info.track(i);
// Prefer title and artist from the track credits, but
// it appears to be empty if same as in Recording
// Noticable in the musicbrainztest-fulldate test,
// where the title on the credits of track 18 are
// "Bara om min älskade väntar", but the recording
// has title "Men bara om min älskade"
if(Recording && Track->ArtistCredit() == 0)
track.set(Artist, artistFromCreditList(Recording->ArtistCredit()));
else
track.set(Artist, artistFromCreditList(Track->ArtistCredit()));
if(Recording && Track->Title().empty())
track.set(Title, QString::fromUtf8(Recording->Title().c_str()));
else
track.set(Title, QString::fromUtf8(Track->Title().c_str()));
}
}
cdInfoList_ << info;
relnr++;
}
}
}
}
}
}
catch (MusicBrainz5::CConnectionError& Error)
{
kDebug() << "Connection Exception: '" << Error.what() << "'";
kDebug() << "LastResult: " << Query.LastResult();
kDebug() << "LastHTTPCode: " << Query.LastHTTPCode();
kDebug() << "LastErrorMessage: " << QString::fromUtf8(Query.LastErrorMessage().c_str());
return ServerError;
}
catch (MusicBrainz5::CTimeoutError& Error)
{
kDebug() << "Timeout Exception: '" << Error.what() << "'";
kDebug() << "LastResult: " << Query.LastResult();
kDebug() << "LastHTTPCode: " << Query.LastHTTPCode();
kDebug() << "LastErrorMessage: " << QString::fromUtf8(Query.LastErrorMessage().c_str());
return ServerError;
}
catch (MusicBrainz5::CAuthenticationError& Error)
{
kDebug() << "Authentication Exception: '" << Error.what() << "'";
kDebug() << "LastResult: " << Query.LastResult();
kDebug() << "LastHTTPCode: " << Query.LastHTTPCode();
kDebug() << "LastErrorMessage: " << QString::fromUtf8(Query.LastErrorMessage().c_str());
return ServerError;
}
catch (MusicBrainz5::CFetchError& Error)
{
kDebug() << "Fetch Exception: '" << Error.what() << "'";
kDebug() << "LastResult: " << Query.LastResult();
kDebug() << "LastHTTPCode: " << Query.LastHTTPCode();
kDebug() << "LastErrorMessage: " << QString::fromUtf8(Query.LastErrorMessage().c_str());
return ServerError;
}
catch (MusicBrainz5::CRequestError& Error)
{
kDebug() << "Request Exception: '" << Error.what() << "'";
kDebug() << "LastResult: " << Query.LastResult();
kDebug() << "LastHTTPCode: " << Query.LastHTTPCode();
kDebug() << "LastErrorMessage: " << QString::fromUtf8(Query.LastErrorMessage().c_str());
return ServerError;
}
catch (MusicBrainz5::CResourceNotFoundError& Error)
{
kDebug() << "ResourceNotFound Exception: '" << Error.what() << "'";
kDebug() << "LastResult: " << Query.LastResult();
kDebug() << "LastHTTPCode: " << Query.LastHTTPCode();
kDebug() << "LastErrorMessage: " << QString::fromUtf8(Query.LastErrorMessage().c_str());
return ServerError;
}
if (cdInfoList_.isEmpty())
{
kDebug() << "No record found";
return NoRecordFound;
}
kDebug() << "Query succeeded :-)";
return Success;
}
QString MusicBrainzLookup::calculateDiscId(const TrackOffsetList & trackOffsetList )
{
// Code based on libmusicbrainz/lib/diskid.cpp
int numTracks = trackOffsetList.count()-1;
QCryptographicHash sha(QCryptographicHash::Sha1);
char temp[9];
// FIXME How do I check that?
int firstTrack = 1;
int lastTrack = numTracks;
sprintf(temp, "%02X", firstTrack);
sha.addData(temp, strlen(temp));
sprintf(temp, "%02X", lastTrack);
sha.addData(temp, strlen(temp));
for(int i = 0; i < 100; i++)
{
long offset;
if (i == 0)
offset = trackOffsetList[numTracks];
else if (i <= numTracks)
offset = trackOffsetList[i-1];
else
offset = 0;
sprintf(temp, "%08lX", offset);
sha.addData(temp, strlen(temp));
}
QByteArray base64 = sha.result().toBase64();
// '/' '+' and '=' replaced for MusicBrainz
QString res = QString::fromLatin1(base64).replace(QLatin1Char( '/' ),QLatin1String( "_" )).replace(QLatin1Char( '+' ),QLatin1String( "." )).replace(QLatin1Char( '=' ),QLatin1String( "-" ));
return res;
}
CDInfoList MusicBrainzLookup::cacheFiles(const TrackOffsetList &offsetList, const Config& c )
{
CDInfoList infoList;
QStringList cddbCacheDirs = c.cacheLocations();
QString discid = calculateDiscId(offsetList);
for (QStringList::const_iterator cddbCacheDir = cddbCacheDirs.constBegin();
cddbCacheDir != cddbCacheDirs.constEnd(); ++cddbCacheDir)
{
// Looks for all files in cddbdir/musicbrainz/discid*
// Several files can correspond to the same discid,
// then they are named discid, discid-2, discid-3 and so on
QDir dir(*cddbCacheDir+QLatin1String( "/musicbrainz/" ));
dir.setNameFilters(QStringList(discid+QLatin1String( "*" )));
QStringList files = dir.entryList();
kDebug() << "Cache files found: " << files.count();
for (QStringList::iterator it = files.begin(); it != files.end(); ++it)
{
QFile f( dir.filePath(*it) );
if ( f.exists() && f.open(QIODevice::ReadOnly) )
{
QTextStream ts(&f);
ts.setCodec("UTF-8");
QString cddbData = ts.readAll();
f.close();
CDInfo info;
info.load(cddbData);
info.set(QLatin1String( "source" ), QLatin1String( "musicbrainz" ));
info.set(QLatin1String( "discid" ), discid);
infoList.append( info );
}
else
kDebug() << "Could not read file: " << f.fileName();
}
}
return infoList;
}
QString MusicBrainzLookup::artistFromCreditList(MusicBrainz5::CArtistCredit * artistCredit )
{
kDebug() << k_funcinfo;
QString artistName;
MusicBrainz5::CNameCreditList *ArtistList=artistCredit->NameCreditList();
if (ArtistList)
{
for (int i=0; i < ArtistList->NumItems(); i++)
{
MusicBrainz5::CNameCredit* Name=ArtistList->Item(i);
MusicBrainz5::CArtist* Artist = Name->Artist();
if (!Name->Name().empty())
artistName += QString::fromUtf8(Name->Name().c_str());
else
artistName += QString::fromUtf8(Artist->Name().c_str());
artistName += QString::fromUtf8(Name->JoinPhrase().c_str());
}
kDebug() << "Artist:" << artistName;
}
return artistName;
}
}
// vim:tabstop=2:shiftwidth=2:expandtab:cinoptions=(s,U1,m1
#include "moc_musicbrainzlookup.cpp"

View file

@ -0,0 +1,57 @@
/*
Copyright (C) 2005 Richard Lärkäng <nouseforaname@home.se>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#ifndef MUSICBRAINZLOOKUP_H
#define MUSICBRAINZLOOKUP_H
#include "../lookup.h"
#include "../cdinfo.h"
#include "../kcddb.h"
#include "../kcddbconfig.h"
namespace MusicBrainz5
{
class CArtistCredit;
}
namespace KCDDB
{
class MusicBrainzLookup : public Lookup
{
Q_OBJECT
public:
MusicBrainzLookup();
virtual ~MusicBrainzLookup();
// FIXME Only freedb lookup needs the first two arguments (host/port)
virtual Result lookup( const QString &, uint, const TrackOffsetList & );
static CDInfoList cacheFiles(const TrackOffsetList &, const Config& );
private:
static QString calculateDiscId(const TrackOffsetList & );
static QString artistFromCreditList(MusicBrainz5::CArtistCredit * );
} ;
}
#endif // MUSICBRAINZ_H
// vim:tabstop=2:shiftwidth=2:expandtab:cinoptions=(s,U1,m1

113
libkcddb/libkcddb/sites.cpp Normal file
View file

@ -0,0 +1,113 @@
/*
Copyright ( C ) 2004 Richard Lärkäng <nouseforaname@home.se>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or ( at your option ) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#include "sites.h"
#include <kurl.h>
#include <kio/netaccess.h>
#include <kio/job.h>
#include <QTextStream>
#include <kdebug.h>
#include <QRegExp>
namespace KCDDB
{
Sites::Sites()
{
}
QList<Mirror>
Sites::siteList()
{
KUrl url;
url.setProtocol( QLatin1String( "http" ) );
url.setHost( QLatin1String( "freedb.freedb.org" ) );
url.setPort( 80 );
url.setPath( QLatin1String( "/~cddb/cddb.cgi" ) );
url.setQuery( QString::null ); //krazy:exclude=nullstrassign for old broken gcc
QString hello = QString::fromLatin1("%1 %2 %3 %4")
.arg(QLatin1String( "libkcddb-user" ), QLatin1String( "localHost" ), CDDB::clientName(), CDDB::clientVersion());
url.addQueryItem( QLatin1String( "cmd" ), QLatin1String( "sites" ) );
url.addQueryItem( QLatin1String( "hello" ), hello );
url.addQueryItem( QLatin1String( "proto" ), QLatin1String( "5" ) );
QList<Mirror> result;
KIO::Job* job = KIO::get( url, KIO::NoReload, KIO::HideProgressInfo );
QByteArray data;
if( KIO::NetAccess::synchronousRun( job, 0, &data ) )
{
result = readData( data );
}
return result;
}
QList<Mirror>
Sites::readData(const QByteArray& data)
{
QList<Mirror> result;
QTextStream ts(data);
if (CDDB::statusCode(ts.readLine()) != 210)
return result;
while (!ts.atEnd())
{
QString line = ts.readLine();
if (line == QLatin1String( "." ))
break;
result << parseLine(line);
}
return result;
}
Mirror
Sites::parseLine(const QString& line)
{
Mirror m;
QRegExp rexp(QLatin1String( "([^ ]+) (cddbp|http) (\\d+) ([^ ]+) [N|S]\\d{3}.\\d{2} [E|W]\\d{3}.\\d{2} (.*)" ));
if (rexp.indexIn(line) != -1)
{
m.address = rexp.cap(1);
if (rexp.cap(2) == QLatin1String( "cddbp" ))
m.transport = Lookup::CDDBP;
else
m.transport = Lookup::HTTP;
m.port = rexp.cap(3).toUInt();
if (m.transport == Lookup::HTTP && rexp.cap(4) != QLatin1String( "/~cddb/cddb.cgi" ))
kWarning() << "Non default urls are not supported for http";
m.description = rexp.cap(5);
}
return m;
}
}

53
libkcddb/libkcddb/sites.h Normal file
View file

@ -0,0 +1,53 @@
/*
Copyright ( C ) 2004 Richard Lärkäng <nouseforaname@home.se>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or ( at your option ) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#ifndef KCDDB_SITES_H
#define KCDDB_SITES_H
#include <QtCore/QList>
#include <libkcddb/cddb.h>
#include <libkcddb/lookup.h>
#include <libkcddb/kcddb_export.h>
namespace KCDDB
{
class Mirror
{
public:
QString address;
Lookup::Transport transport;
uint port;
QString description;
} ;
class KCDDB_EXPORT Sites
{
public:
Sites();
QList<Mirror> siteList();
private:
QList<Mirror> readData(const QByteArray& data);
Mirror parseLine(const QString& line);
} ;
}
#endif
// vim:tabstop=2:shiftwidth=2:expandtab:cinoptions=(s,U1,m1

View file

@ -0,0 +1,61 @@
/*
Copyright (C) 2003 Richard Lärkäng <nouseforaname@home.se>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#include "smtpsubmit.h"
#include <kdebug.h>
#include <kio/job.h>
namespace KCDDB
{
SMTPSubmit::SMTPSubmit(const QString& hostname, uint port, const QString& username,
const QString& from, const QString& to)
: Submit(), from_(from), to_(to)
{
url_.setProtocol(QLatin1String( "smtp" ));
url_.setHost(hostname);
url_.setPort(port);
if (!username.isEmpty())
url_.setUser(username);
url_.setPath(QLatin1String( "/send" ));
}
SMTPSubmit::~SMTPSubmit()
{
}
KIO::Job* SMTPSubmit::createJob(const CDInfo& cdInfo)
{
url_.setQuery(QString::fromLatin1("to=%1&subject=cddb %2 %3&from=%4")
.arg(to_, cdInfo.get(Category).toString(),
cdInfo.get(QLatin1String( "discid" )).toString(), from_));
kDebug(60010) << "Url is: " << url_.prettyUrl();
return KIO::storedPut(diskData_.toUtf8().data(), url_, -1, KIO::HideProgressInfo);
}
void SMTPSubmit::makeDiskData( const CDInfo& cdInfo, const TrackOffsetList& offsetList )
{
diskData_ = QLatin1String( "Content-Type: text/plain; charset=\"utf-8\";\n" );
Submit::makeDiskData(cdInfo, offsetList);
}
}

View file

@ -0,0 +1,43 @@
#ifndef SMTPSUBMIT_H
#define SMTPSUBMIT_H
/*
Copyright (C) 2003 Richard Lärkäng <nouseforaname@home.se>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#include "submit.h"
#include <kurl.h>
namespace KCDDB
{
class SMTPSubmit : public Submit
{
public:
SMTPSubmit(const QString& hostname, uint port, const QString& username, const QString& from, const QString& to);
virtual ~SMTPSubmit();
protected:
virtual void makeDiskData( const CDInfo&, const TrackOffsetList& );
virtual KIO::Job* createJob(const CDInfo& cdInfo);
KUrl url_;
QString from_, to_;
} ;
}
#endif // SMTPSUBMIT_H

View file

@ -0,0 +1,102 @@
/*
Copyright (C) 2002 Rik Hemsley (rikkus) <rik@kde.org>
Copyright (C) 2002 Benjamin Meyer <ben-devel@meyerhome.net>
Copyright (C) 2003-2005 Richard Lärkäng <nouseforaname@home.se>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#include "submit.h"
#include <kdebug.h>
namespace KCDDB
{
Submit::Submit()
: CDDB()
{
// Empty.
}
Submit::~Submit()
{
// Empty.
}
Result Submit::submit( CDInfo cdInfo, const TrackOffsetList& offsetList)
{
// If it was an inexact math from the server the discid might
// be different, so recalculate it
cdInfo.set(QLatin1String( "discid" ), trackOffsetListToId(offsetList));
makeDiskData( cdInfo, offsetList );
if (!validCategory(cdInfo.get(Category).toString()))
return InvalidCategory;
KIO::Job* job = createJob(cdInfo);
if (!job)
return UnknownError;
return runJob(job);
}
Result
Submit::parseWrite( const QString & line )
{
uint serverStatus = statusCode( line );
if ( 320 != serverStatus )
return ServerError;
return Success;
}
void Submit::makeDiskData( const CDInfo& cdInfo, const TrackOffsetList& offsetList )
{
unsigned numTracks = cdInfo.numberOfTracks();
diskData_ += QLatin1String( "# xmcd\n" );
diskData_ += QLatin1String( "#\n" );
diskData_ += QLatin1String( "# Track frame offsets:\n" );
for (uint i=0; i < numTracks; i++)
diskData_ += QString::fromLatin1("#\t%1\n").arg(offsetList[i]);
int l = offsetList[numTracks]/75;
diskData_ += QString::fromLatin1("# Disc length: %1 seconds\n").arg(l);
diskData_ += cdInfo.toString(true);
kDebug(60010) << "diskData_ == " << diskData_;
}
bool Submit::validCategory( const QString& c )
{
QStringList validCategories;
validCategories << QLatin1String( "blues" ) << QLatin1String( "classical" ) << QLatin1String( "country" )
<< QLatin1String( "data" ) << QLatin1String( "folk" ) << QLatin1String( "jazz" ) << QLatin1String( "misc" ) << QLatin1String( "newage" ) << QLatin1String( "reggae" )
<< QLatin1String( "rock" ) << QLatin1String( "soundtrack" );
if (validCategories.contains(c))
return true;
else
return false;
}
}
// vim:tabstop=2:shiftwidth=2:expandtab:cinoptions=(s,U1,m1

View file

@ -0,0 +1,65 @@
/*
Copyright (C) 2002 Rik Hemsley (rikkus) <rik@kde.org>
Copyright (C) 2002 Benjamin Meyer <ben-devel@meyerhome.net>
Copyright (C) 2002 Nadeem Hasan <nhasan@kde.org>
Copyright (C) 2005 Richard Lärkäng <nouseforaname@home.se>e>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#ifndef KCDDB_SUBMIT_H
#define KCDDB_SUBMIT_H
#include "cddb.h"
#include "cdinfo.h"
#include <QObject>
namespace KIO
{
class Job;
}
namespace KCDDB
{
class Submit : public CDDB, public QObject
{
public:
enum Transport
{
HTTP,
SMTP
};
Submit();
virtual ~Submit();
Result submit( CDInfo cdInfo, const TrackOffsetList &offsetList);
protected:
virtual KIO::Job* createJob(const CDInfo& cdInfo) = 0;
virtual Result runJob(KIO::Job* job) = 0;
bool validCategory(const QString&);
Result parseWrite( const QString & );
virtual void makeDiskData( const CDInfo&, const TrackOffsetList& );
QString diskData_;
};
}
#endif // KCDDB_SUBMIT_H
// vim:tabstop=2:shiftwidth=2:expandtab:cinoptions=(s,U1,m1

View file

@ -0,0 +1,203 @@
/*
Copyright (C) 2002 Rik Hemsley (rikkus) <rik@kde.org>
Copyright (C) 2002 Benjamin Meyer <ben-devel@meyerhome.net>
Copyright (C) 2005 Richard Lärkäng <nouseforaname@home.se>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#include "synccddbplookup.h"
#include <qstringlist.h>
#include <kdebug.h>
#include <ksocketfactory.h>
namespace KCDDB
{
SyncCDDBPLookup::SyncCDDBPLookup()
: CDDBPLookup()
{
}
SyncCDDBPLookup::~SyncCDDBPLookup()
{
// Empty.
}
Result
SyncCDDBPLookup::lookup
(
const QString & hostName,
uint port,
const TrackOffsetList & trackOffsetList
)
{
trackOffsetList_ = trackOffsetList;
socket_ = KSocketFactory::synchronousConnectToHost(QLatin1String( "cddbp" ), hostName, port);
if ( !socket_->isValid() )
{
kDebug(60010) << "Couldn't connect to " << socket_->peerName() << ":" << socket_->peerPort();
kDebug(60010) << "Socket error: " << socket_->errorString();
if ( socket_->error() == QAbstractSocket::HostNotFoundError )
return HostNotFound;
else if ( socket_->error() == QAbstractSocket::SocketTimeoutError )
return NoResponse;
else
return UnknownError;
}
Result result;
// Try a handshake.
result = shakeHands();
if ( Success != result )
return result;
// Run a query.
result = runQuery();
if ( Success != result )
return result;
if (matchList_.isEmpty())
return NoRecordFound;
kDebug(60010) << matchList_.count() << " matches found.";
// For each match, read the cd info from the server and save it to
// cdInfoList.
CDDBMatchList::ConstIterator matchIt = matchList_.constBegin();
while ( matchIt != matchList_.constEnd() )
{
CDDBMatch match( *matchIt );
result = matchToCDInfo( match );
++matchIt;
}
sendQuit();
close();
return Success;
}
Result
SyncCDDBPLookup::shakeHands()
{
QString line = readLine();
if ( !parseGreeting( line ) )
return ServerError;
sendHandshake();
line = readLine();
if ( !parseHandshake( line ) )
return ServerError;
sendProto();
// Ignore the response for now
readLine();
return Success;
}
Result
SyncCDDBPLookup::runQuery()
{
Result result;
sendQuery();
QString line = readLine();
result = parseQuery( line );
if ( ServerError == result )
return ServerError;
if ( MultipleRecordFound == result )
{
// We have multiple matches
line = readLine();
while (!line.startsWith(QLatin1String( "." )) && !line.isNull() )
{
parseExtraMatch( line );
line = readLine();
}
}
return Success;
}
Result
SyncCDDBPLookup::matchToCDInfo( const CDDBMatch & match )
{
sendRead( match );
QString line = readLine();
Result result = parseRead( line );
if ( Success != result )
return result;
QStringList lineList;
line = readLine();
while ( !line.startsWith(QLatin1String( "." )) && !line.isNull() )
{
lineList.append( line );
line = readLine();
}
CDInfo info;
if ( info.load( lineList ) )
{
info.set( QLatin1String( "category" ), category_ );
info.set( QLatin1String( "discid" ), discid_ );
info.set( QLatin1String( "source" ), QLatin1String( "freedb" ) );
cdInfoList_.append( info );
}
return Success;
}
QString
SyncCDDBPLookup::readLine()
{
if ( !isConnected() )
{
kDebug(60010) << "socket status: " << socket_->state();
return QString();
}
if (!socket_->canReadLine())
{
if (!socket_->waitForReadyRead(-1))
return QString();
}
return QString::fromUtf8(socket_->readLine());
}
}
// vim:tabstop=2:shiftwidth=2:expandtab:cinoptions=(s,U1,m1

View file

@ -0,0 +1,50 @@
/*
Copyright (C) 2002 Rik Hemsley (rikkus) <rik@kde.org>
Copyright (C) 2002 Benjamin Meyer <ben-devel@meyerhome.net>
Copyright (C) 2002 Nadeem Hasan <nhasan@kde.org>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#ifndef KCDDB_SYNC_CDDBP_LOOKUP_H
#define KCDDB_SYNC_CDDBP_LOOKUP_H
#include "cddbplookup.h"
namespace KCDDB
{
class SyncCDDBPLookup : public CDDBPLookup
{
public:
SyncCDDBPLookup();
virtual ~SyncCDDBPLookup();
Result lookup( const QString &, uint, const TrackOffsetList & );
CDInfoList lookupResponse() const;
protected:
Result shakeHands();
Result runQuery();
Result matchToCDInfo( const CDDBMatch & );
QString readLine();
};
}
#endif // KCDDB_SYNC_CDDBP_LOOKUP_H
// vim:tabstop=2:shiftwidth=2:expandtab:cinoptions=(s,U1,m1

View file

@ -0,0 +1,128 @@
/*
Copyright (C) 2002 Rik Hemsley (rikkus) <rik@kde.org>
Copyright (C) 2002 Benjamin Meyer <ben-devel@meyerhome.net>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#include "synchttplookup.h"
#include <qstringlist.h>
#include <qapplication.h>
#include <kdebug.h>
#include <kio/job.h>
#include <kio/netaccess.h>
namespace KCDDB
{
SyncHTTPLookup::SyncHTTPLookup()
: HTTPLookup()
{
}
SyncHTTPLookup::~SyncHTTPLookup()
{
// Empty.
}
Result
SyncHTTPLookup::lookup
(
const QString & hostName,
uint port,
const TrackOffsetList & trackOffsetList
)
{
trackOffsetList_ = trackOffsetList;
initURL( hostName, port );
// Run a query.
result_ = runQuery();
if ( Success != result_ )
return result_;
kDebug(60010) << matchList_.count() << " matches found.";
if (matchList_.isEmpty())
return NoRecordFound;
// For each match, read the cd info from the server and save it to
// cdInfoList.
CDDBMatchList::ConstIterator matchIt = matchList_.constBegin();
while ( matchIt != matchList_.constEnd() )
{
CDDBMatch match( *matchIt );
result_ = matchToCDInfo( match );
++matchIt;
}
return result_;
}
Result
SyncHTTPLookup::runQuery()
{
data_ = QByteArray();
state_ = WaitingForQueryResponse;
result_ = sendQuery();
if ( Success != result_ )
return result_;
kDebug(60010) << "runQuery() Result: " << resultToString(result_);
return result_;
}
Result
SyncHTTPLookup::matchToCDInfo( const CDDBMatch & match )
{
data_ = QByteArray();
state_ = WaitingForReadResponse;
result_ = sendRead( match );
if ( Success != result_ )
return result_;
return result_;
}
Result
SyncHTTPLookup::fetchURL()
{
kDebug(60010) << "About to fetch: " << cgiURL_.url();
KIO::TransferJob* job = KIO::get( cgiURL_, KIO::NoReload, KIO::HideProgressInfo );
if ( 0 == job )
return ServerError;
if (!KIO::NetAccess::synchronousRun(job, 0, &data_))
return ServerError;
jobFinished();
return Success;
}
}
// vim:tabstop=2:shiftwidth=2:expandtab:cinoptions=(s,U1,m1

View file

@ -0,0 +1,50 @@
/*
Copyright (C) 2002 Rik Hemsley (rikkus) <rik@kde.org>
Copyright (C) 2002 Benjamin Meyer <ben-devel@meyerhome.net>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#ifndef KCDDB_SYNC_HTTP_LOOKUP_H
#define KCDDB_SYNC_HTTP_LOOKUP_H
#include "httplookup.h"
namespace KCDDB
{
class SyncHTTPLookup : public HTTPLookup
{
public:
SyncHTTPLookup();
virtual ~SyncHTTPLookup();
Result lookup( const QString &, uint, const TrackOffsetList & );
CDInfoList lookupResponse() const;
protected:
virtual Result fetchURL();
Result runQuery();
Result matchToCDInfo( const CDDBMatch & );
};
}
#endif // KCDDB_SYNC_HTTP_LOOKUP_H
// vim:tabstop=2:shiftwidth=2:expandtab:cinoptions=(s,U1,m1

View file

@ -0,0 +1,47 @@
/*
Copyright (C) 2003 Richard Lärkäng <nouseforaname@home.se>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#include "synchttpsubmit.h"
#include <kio/netaccess.h>
#include <kio/job.h>
namespace KCDDB
{
SyncHTTPSubmit::SyncHTTPSubmit(const QString& from, const QString& hostname, uint port)
: HTTPSubmit(from, hostname, port)
{
}
SyncHTTPSubmit::~SyncHTTPSubmit()
{
}
Result SyncHTTPSubmit::runJob(KIO::Job* job)
{
bool success = KIO::NetAccess::synchronousRun(job, 0);
if (success)
return Success;
else
return UnknownError;
}
}

View file

@ -0,0 +1,37 @@
#ifndef SYNCHTTPSUBMIT_H
#define SYNCHTTPSUBMIT_H
/*
Copyright (C) 2003 Richard Lärkäng <nouseforaname@home.se>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#include "httpsubmit.h"
namespace KCDDB
{
class SyncHTTPSubmit : public HTTPSubmit
{
public:
SyncHTTPSubmit(const QString& from, const QString& hostname, uint port);
virtual ~SyncHTTPSubmit();
protected:
virtual Result runJob(KIO::Job* job);
} ;
}
#endif // SYNCHTTPSUBMIT_H

View file

@ -0,0 +1,48 @@
/*
Copyright (C) 2003-2004 Richard Lärkäng <nouseforaname@home.se>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#include "syncsmtpsubmit.h"
#include "cdinfo.h"
#include <kio/netaccess.h>
#include <kio/job.h>
namespace KCDDB
{
SyncSMTPSubmit::SyncSMTPSubmit(const QString& hostname, uint port,
const QString& username, const QString& from, const QString& to)
: SMTPSubmit( hostname, port, username, from, to )
{
}
SyncSMTPSubmit::~SyncSMTPSubmit()
{
}
Result SyncSMTPSubmit::runJob(KIO::Job* job)
{
if ( KIO::NetAccess::synchronousRun(job, 0) )
return Success;
return UnknownError;
}
}

View file

@ -0,0 +1,38 @@
#ifndef SYNCSMTPSUBMIT_H
#define SYNCSMTPSUBMIT_H
/*
Copyright (C) 2003 Richard Lärkäng <nouseforaname@home.se>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#include "smtpsubmit.h"
namespace KCDDB
{
class SyncSMTPSubmit : public SMTPSubmit
{
public:
SyncSMTPSubmit(const QString& hostname, uint port, const QString& username,
const QString& from, const QString& to);
virtual ~SyncSMTPSubmit();
protected:
virtual Result runJob(KIO::Job* job);
} ;
}
#endif // SYNCSMTPSUBMIT_H
// vim:tabstop=2:shiftwidth=2:expandtab:cinoptions=(s,U1,m1

View file

@ -0,0 +1,42 @@
set( EXECUTABLE_OUTPUT_PATH ${CMAKE_CURRENT_BINARY_DIR} )
include_directories( ${CMAKE_CURRENT_SOURCE_DIR}/.. ${CMAKE_CURRENT_BINARY_DIR}/../libkcddb )
MACRO(KCDDB_EXECUTABLE_TESTS)
FOREACH(_testname ${ARGN})
kde4_add_executable(${_testname} TEST ${_testname}.cpp)
target_link_libraries(${_testname} ${KDE4_KDEUI_LIBS}
${QT_QTTEST_LIBRARY} kcddb)
ENDFOREACH(_testname)
ENDMACRO(KCDDB_EXECUTABLE_TESTS)
MACRO(KCDDB_UNIT_TESTS)
FOREACH(_testname ${ARGN})
kde4_add_unit_test(${_testname} TESTNAME kcddb-${_testname} ${_testname}.cpp)
target_link_libraries(${_testname} ${KDE4_KDEUI_LIBS}
${QT_QTTEST_LIBRARY} kcddb)
ENDFOREACH(_testname)
ENDMACRO(KCDDB_UNIT_TESTS)
KCDDB_UNIT_TESTS(
asynchttplookuptest
asynccddblookuptest
synccddblookuptest
synchttplookuptest
utf8test
musicbrainztest
asyncmusicbrainztest
cdinfotest
cachetest
musicbrainztest-severaldiscs
musicbrainztest-fulldate
)
KCDDB_EXECUTABLE_TESTS(
syncsmtpsubmittest
asyncsmtpsubmittest
asynchttpsubmittest
synchttpsubmittest
sitestest
)

View file

@ -0,0 +1,119 @@
/*
Copyright (C) 2006 Richard Lärkäng <nouseforaname@home.se>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#include <qtest_kde.h>
#include "asynccddblookuptest.h"
#include "libkcddb/cache.h"
#include "libkcddb/lookup.h"
void AsyncCDDBLookupTest::testLookup()
{
using namespace KCDDB;
client_ = new Client;
client_->config().setHostname("freedb.freedb.org");
client_->config().setPort(8880);
client_->config().setCacheLookupEnabled(false);
client_->config().setFreedbLookupEnabled(true);
client_->config().setMusicBrainzLookupEnabled(false);
client_->config().setFreedbLookupTransport(Lookup::CDDBP);
client_->setBlockingMode( false );
connect(client_,SIGNAL(finished(KCDDB::Result)),SLOT(slotFinished(KCDDB::Result)));
TrackOffsetList list;
// a1107d0a - Kruder & Dorfmeister - The K&D Sessions - Disc One.
list
<< 150 // First track start.
<< 29462
<< 66983
<< 96785
<< 135628
<< 168676
<< 194147
<< 222158
<< 247076
<< 278203 // Last track start.
<< 316732; // Disc end.
client_->lookup(list);
m_eventLoop.exec(QEventLoop::ExcludeUserInputEvents);
delete client_;
QVERIFY(m_result == Success);
// If revision doesn't match, test probably needs to be updated
// See: http://www.freedb.org/freedb/jazz/a1107d0a for updated data
QCOMPARE(m_info.get("revision").toInt(), 7);
QCOMPARE(m_info.get(Artist).toString(),QString("Kruder & Dorfmeister"));
QCOMPARE(m_info.get(Title).toString(),QString("The K&D Sessions (Part One)"));
QCOMPARE(m_info.get(Genre).toString(),QString("Trip-Hop"));
QCOMPARE(m_info.get(Year).toInt(),1998);
QCOMPARE(m_info.track(0).get(Title).toString(),QString("Roni Size - Heroes (Kruder's Long Loose Bossa remixed by Peter Kruder)"));
QCOMPARE(m_info.track(1).get(Title).toString(),QString("Alex Reece - Jazz Master (K&D Session)"));
QCOMPARE(m_info.track(2).get(Title).toString(),QString("Count Basic - Speechless (Drum 'n' Bass remixed by Peter Kruder)"));
QCOMPARE(m_info.track(3).get(Title).toString(),QString("Rockers Hi-Fi - Going Under (K&D Session)"));
QCOMPARE(m_info.track(4).get(Title).toString(),QString("Bomb The Bass - Bug Powder Dust (K&D Session)"));
QCOMPARE(m_info.track(5).get(Title).toString(),QString("Aphrodelics - Rollin' On Chrome (Wild Motherfucker Dub remixed by Richard Dorfmeister)"));
QCOMPARE(m_info.track(6).get(Title).toString(),QString("Depeche Mode - Useless (K&D Session)"));
QCOMPARE(m_info.track(7).get(Title).toString(),QString("Count Basic - Gotta Jazz (remixed by Richard Dorfmeister)"));
QCOMPARE(m_info.track(8).get(Title).toString(),QString("Rainer Truby Trio - Donaueschingen (Peter Kruder's Donaudampfschifffahrtsgesellschaftskapitnskajtenremix)"));
QCOMPARE(m_info.track(9).get(Title).toString(),QString("Lamb - Trans Fatty Acid (K&D Session)"));
QCOMPARE(m_info.track(0).get(Artist).toString(),QString("Kruder & Dorfmeister"));
QCOMPARE(m_info.track(1).get(Artist).toString(),QString("Kruder & Dorfmeister"));
QCOMPARE(m_info.track(2).get(Artist).toString(),QString("Kruder & Dorfmeister"));
QCOMPARE(m_info.track(3).get(Artist).toString(),QString("Kruder & Dorfmeister"));
QCOMPARE(m_info.track(4).get(Artist).toString(),QString("Kruder & Dorfmeister"));
QCOMPARE(m_info.track(5).get(Artist).toString(),QString("Kruder & Dorfmeister"));
QCOMPARE(m_info.track(6).get(Artist).toString(),QString("Kruder & Dorfmeister"));
QCOMPARE(m_info.track(7).get(Artist).toString(),QString("Kruder & Dorfmeister"));
QCOMPARE(m_info.track(8).get(Artist).toString(),QString("Kruder & Dorfmeister"));
QCOMPARE(m_info.track(9).get(Artist).toString(),QString("Kruder & Dorfmeister"));
}
void
AsyncCDDBLookupTest::slotFinished(Result r)
{
m_result = r;
kDebug() << "AsyncCDDBLookupTest::slotResult: Got " << KCDDB::resultToString(r);
CDInfoList l = client_->lookupResponse();
kDebug() << "AsyncCDDBLookupTest::slotResult: Item count: " << l.count();
foreach(const CDInfo &i, l)
{
if (i.get("discid") == "a1107d0a" && i.get(Category) == "jazz")
{
kDebug() << "Found the CD";
m_info = i;
break;
}
}
m_eventLoop.quit();
}
QTEST_KDEMAIN(AsyncCDDBLookupTest, NoGUI)
#include "moc_asynccddblookuptest.cpp"

View file

@ -0,0 +1,45 @@
/*
Copyright (C) 2003 Richard Lärkäng <nouseforaname@home.se>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#ifndef TEST_H
#define TEST_H
#include <QEventLoop>
#include <QObject>
#include <libkcddb/client.h>
#include <libkcddb/kcddb.h>
using namespace KCDDB;
class AsyncCDDBLookupTest : public QObject
{
Q_OBJECT
private slots:
void testLookup();
void slotFinished(KCDDB::Result);
private:
QEventLoop m_eventLoop;
KCDDB::Client * client_;
CDInfo m_info;
Result m_result;
};
#endif

View file

@ -0,0 +1,120 @@
/*
Copyright (C) 2006 Richard Lärkäng <nouseforaname@home.se>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#include <qtest_kde.h>
#include "asynchttplookuptest.h"
#include "libkcddb/cache.h"
#include "libkcddb/lookup.h"
void AsyncHTTPLookupTest::testLookup()
{
using namespace KCDDB;
client_ = new Client;
client_->config().setHostname("freedb.freedb.org");
client_->config().setPort(80);
client_->config().setCacheLookupEnabled(false);
client_->config().setFreedbLookupEnabled(true);
client_->config().setMusicBrainzLookupEnabled(false);
client_->config().setFreedbLookupTransport(Lookup::HTTP);
client_->setBlockingMode( false );
connect(client_, SIGNAL(finished(KCDDB::Result)), SLOT(slotFinished(KCDDB::Result)));
TrackOffsetList list;
// a1107d0a - Kruder & Dorfmeister - The K&D Sessions - Disc One.
list
<< 150 // First track start.
<< 29462
<< 66983
<< 96785
<< 135628
<< 168676
<< 194147
<< 222158
<< 247076
<< 278203 // Last track start.
<< 316732; // Disc end.
client_->lookup(list);
m_eventLoop.exec(QEventLoop::ExcludeUserInputEvents);
delete client_;
QVERIFY(m_result == Success);
// If revision doesn't match, test probably needs to be updated
// See: http://www.freedb.org/freedb/jazz/a1107d0a for updated data
QCOMPARE(m_info.get("revision").toInt(), 7);
QCOMPARE(m_info.get(Artist).toString(),QString("Kruder & Dorfmeister"));
QCOMPARE(m_info.get(Title).toString(),QString("The K&D Sessions (Part One)"));
QCOMPARE(m_info.get(Genre).toString(),QString("Trip-Hop"));
QCOMPARE(m_info.get(Year).toInt(),1998);
QCOMPARE(m_info.track(0).get(Title).toString(),QString("Roni Size - Heroes (Kruder's Long Loose Bossa remixed by Peter Kruder)"));
QCOMPARE(m_info.track(1).get(Title).toString(),QString("Alex Reece - Jazz Master (K&D Session)"));
QCOMPARE(m_info.track(2).get(Title).toString(),QString("Count Basic - Speechless (Drum 'n' Bass remixed by Peter Kruder)"));
QCOMPARE(m_info.track(3).get(Title).toString(),QString("Rockers Hi-Fi - Going Under (K&D Session)"));
QCOMPARE(m_info.track(4).get(Title).toString(),QString("Bomb The Bass - Bug Powder Dust (K&D Session)"));
QCOMPARE(m_info.track(5).get(Title).toString(),QString("Aphrodelics - Rollin' On Chrome (Wild Motherfucker Dub remixed by Richard Dorfmeister)"));
QCOMPARE(m_info.track(6).get(Title).toString(),QString("Depeche Mode - Useless (K&D Session)"));
QCOMPARE(m_info.track(7).get(Title).toString(),QString("Count Basic - Gotta Jazz (remixed by Richard Dorfmeister)"));
QCOMPARE(m_info.track(8).get(Title).toString(),QString("Rainer Truby Trio - Donaueschingen (Peter Kruder's Donaudampfschifffahrtsgesellschaftskapitnskajtenremix)"));
QCOMPARE(m_info.track(9).get(Title).toString(),QString("Lamb - Trans Fatty Acid (K&D Session)"));
QCOMPARE(m_info.track(0).get(Artist).toString(),QString("Kruder & Dorfmeister"));
QCOMPARE(m_info.track(1).get(Artist).toString(),QString("Kruder & Dorfmeister"));
QCOMPARE(m_info.track(2).get(Artist).toString(),QString("Kruder & Dorfmeister"));
QCOMPARE(m_info.track(3).get(Artist).toString(),QString("Kruder & Dorfmeister"));
QCOMPARE(m_info.track(4).get(Artist).toString(),QString("Kruder & Dorfmeister"));
QCOMPARE(m_info.track(5).get(Artist).toString(),QString("Kruder & Dorfmeister"));
QCOMPARE(m_info.track(6).get(Artist).toString(),QString("Kruder & Dorfmeister"));
QCOMPARE(m_info.track(7).get(Artist).toString(),QString("Kruder & Dorfmeister"));
QCOMPARE(m_info.track(8).get(Artist).toString(),QString("Kruder & Dorfmeister"));
QCOMPARE(m_info.track(9).get(Artist).toString(),QString("Kruder & Dorfmeister"));
}
void
AsyncHTTPLookupTest::slotFinished(Result r)
{
m_result = r;
kDebug() << "AsyncHTTPLookupTest::slotFinished: Got " << KCDDB::resultToString(r);
CDInfoList l = client_->lookupResponse();
kDebug() << "AsyncHTTPLookupTest::slotFinished: Item count: " << l.count();
foreach(const CDInfo &i, l)
{
if (i.get("discid") == "a1107d0a" && i.get(Category) == "jazz")
{
kDebug() << "Found the CD";
m_info = i;
break;
}
}
m_eventLoop.quit();
}
QTEST_KDEMAIN(AsyncHTTPLookupTest, NoGUI)
#include "moc_asynchttplookuptest.cpp"

View file

@ -0,0 +1,45 @@
/*
Copyright (C) 2003 Richard Lärkäng <nouseforaname@home.se>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#ifndef TEST_H
#define TEST_H
#include <QEventLoop>
#include <QObject>
#include <libkcddb/client.h>
#include <libkcddb/kcddb.h>
using namespace KCDDB;
class AsyncHTTPLookupTest : public QObject
{
Q_OBJECT
private slots:
void testLookup();
void slotFinished(KCDDB::Result);
private:
QEventLoop m_eventLoop;
KCDDB::Client * client_;
CDInfo m_info;
Result m_result;
};
#endif

View file

@ -0,0 +1,87 @@
/*
Copyright (C) 2006 Richard Lärkäng <nouseforaname@home.se>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#include <kdebug.h>
#include <kapplication.h>
#include <kcmdlineargs.h>
#include "asynchttpsubmittest.h"
#include "libkcddb/submit.h"
AsyncHTTPSubmitTest::AsyncHTTPSubmitTest()
: QObject()
{
using namespace KCDDB;
client_ = new Client;
client_->config().setFreedbSubmitTransport(Submit::HTTP);
client_->setBlockingMode( false );
TrackOffsetList list;
list
<< 150 // First track start.
<< 2592
<< 35472
<< 47891
<< 123310
<< 133125; // Disc end.
CDInfo cdInfo;
cdInfo.set("discid", "3606ed05");
cdInfo.set("revision", 4);
cdInfo.set("title", "Bamse och Bronto");
cdInfo.set("artist", "Musiksage");
cdInfo.set("year", 2001);
cdInfo.set("category", "misc");
cdInfo.set("genre", "Barnsaga");
cdInfo.set("extd", QString::fromUtf8("Berättare: Olof Thunberg"));
cdInfo.track(0).set("title", "Bamses signaturmelodi");
cdInfo.track(1).set("title","*");
cdInfo.track(2).set("title", "Brummavisan");
cdInfo.track(3).set("title", "*");
cdInfo.track(4).set("title", QString::fromUtf8("Jätteödlan Bronto"));
connect(client_,SIGNAL(finished(KCDDB::Result)),SLOT(slotFinished(KCDDB::Result)));
client_->submit(cdInfo, list);
}
void
AsyncHTTPSubmitTest::slotFinished(Result r)
{
kDebug() << "AsyncHTTPSubmitTest::slotFinished: Got " << KCDDB::resultToString(r);
kapp->quit();
}
int main(int argc, char ** argv)
{
KCmdLineArgs::init(argc, argv, "libkcddb_test", 0, KLocalizedString(), "");
KApplication app(false);
new AsyncHTTPSubmitTest;
return app.exec();
}
#include "moc_asynchttpsubmittest.cpp"

View file

@ -0,0 +1,44 @@
/*
Copyright (C) 2004 Richard Lärkäng <nouseforaname@home.se>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#ifndef TEST_H
#define TEST_H
#include <QObject>
#include <libkcddb/client.h>
using namespace KCDDB;
class AsyncHTTPSubmitTest : public QObject
{
Q_OBJECT
public:
AsyncHTTPSubmitTest();
public slots:
void slotFinished(KCDDB::Result);
private:
KCDDB::Client * client_;
};
#endif

View file

@ -0,0 +1,158 @@
/*
Copyright (C) 2006 Richard Lärkäng <nouseforaname@home.se>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#include <qtest_kde.h>
#include "asyncmusicbrainztest.h"
#include "libkcddb/cache.h"
#include "libkcddb/lookup.h"
#include "config-musicbrainz.h"
void AsyncMusicBrainzTest::testLookup()
{
using namespace KCDDB;
#ifndef HAVE_MUSICBRAINZ5
QSKIP("This test requires libmusicbrainz", SkipAll);
#endif
client_ = new Client;
client_->config().setCacheLookupEnabled(false);
client_->config().setFreedbLookupEnabled(false);
client_->config().setMusicBrainzLookupEnabled(true);
client_->setBlockingMode( false );
connect(client_,SIGNAL(finished(KCDDB::Result)),SLOT(slotFinished(KCDDB::Result)));
TrackOffsetList list;
// Various Artists / Definitivt 50 Spänn 10
list
<< 150
<< 17130
<< 26340
<< 44855
<< 60530
<< 75800
<< 90182
<< 106605
<< 122995
<< 139005
<< 153317
<< 167967
<< 179012
<< 190190
<< 202162
<< 211312
<< 229037
<< 240035;
client_->lookup(list);
m_eventLoop.exec(QEventLoop::ExcludeUserInputEvents);
QVERIFY(m_result == Success);
// See http://musicbrainz.org/release/dbb3e39a-4bea-4e32-a546-456654f30ca6.html for changes
QCOMPARE(m_info.numberOfTracks(),17);
QCOMPARE(m_info.get(Artist).toString(),QString("Various Artists"));
QCOMPARE(m_info.get(Title).toString(),QString::fromUtf8("Definitivt 50 spänn 10"));
// genre not really supported for musicbrainz
QCOMPARE(m_info.get(Genre).toString(),QString());
QCOMPARE(m_info.get(Year).toInt(),2001);
QCOMPARE(m_info.track(0).get(Title).toString(),QString::fromUtf8("Uphill Struggle"));
QCOMPARE(m_info.track(1).get(Title).toString(),QString::fromUtf8("Vill du bli miljonär?"));
QCOMPARE(m_info.track(2).get(Title).toString(),QString::fromUtf8("Här är jag"));
QCOMPARE(m_info.track(3).get(Title).toString(),QString::fromUtf8("Århundradets fest"));
QCOMPARE(m_info.track(4).get(Title).toString(),QString::fromUtf8("Vem valde mittemellan"));
QCOMPARE(m_info.track(5).get(Title).toString(),QString::fromUtf8("Hippieambulansen"));
QCOMPARE(m_info.track(6).get(Title).toString(),QString::fromUtf8("Jonsson"));
QCOMPARE(m_info.track(7).get(Title).toString(),QString::fromUtf8("Jag lämnar filmen"));
QCOMPARE(m_info.track(8).get(Title).toString(),QString::fromUtf8("39 Steg"));
QCOMPARE(m_info.track(9).get(Title).toString(),QString::fromUtf8("Lyckliga land"));
QCOMPARE(m_info.track(10).get(Title).toString(),QString::fromUtf8("Helpless"));
QCOMPARE(m_info.track(11).get(Title).toString(),QString::fromUtf8("Tunna skivor"));
QCOMPARE(m_info.track(12).get(Title).toString(),QString::fromUtf8("God läskeblask"));
QCOMPARE(m_info.track(13).get(Title).toString(),QString::fromUtf8("Hur snygg é du då?"));
QCOMPARE(m_info.track(14).get(Title).toString(),QString::fromUtf8("Självupptagen"));
QCOMPARE(m_info.track(15).get(Title).toString(),QString::fromUtf8("Sound Is Compressed; Words Rebel and Hiss"));
QCOMPARE(m_info.track(16).get(Title).toString(),QString::fromUtf8("Vi är på väg"));
QCOMPARE(m_info.track(0).get(Artist).toString(),QString::fromUtf8("Adhesive"));
QCOMPARE(m_info.track(1).get(Artist).toString(),QString::fromUtf8("Troublemakers"));
QCOMPARE(m_info.track(2).get(Artist).toString(),QString::fromUtf8("Mimikry"));
QCOMPARE(m_info.track(3).get(Artist).toString(),QString::fromUtf8("Lundberg & Dellamorte"));
QCOMPARE(m_info.track(4).get(Artist).toString(),QString::fromUtf8("Charta 77"));
QCOMPARE(m_info.track(5).get(Artist).toString(),QString::fromUtf8("UBBA"));
QCOMPARE(m_info.track(6).get(Artist).toString(),QString::fromUtf8("Coca Carola"));
QCOMPARE(m_info.track(7).get(Artist).toString(),QString::fromUtf8("Spoiler"));
QCOMPARE(m_info.track(8).get(Artist).toString(),QString::fromUtf8("Strebers"));
QCOMPARE(m_info.track(9).get(Artist).toString(),QString::fromUtf8("Iguana Party"));
QCOMPARE(m_info.track(10).get(Artist).toString(),QString::fromUtf8("Stoned"));
QCOMPARE(m_info.track(11).get(Artist).toString(),QString::fromUtf8("Per Bertil Birgers orkester"));
QCOMPARE(m_info.track(12).get(Artist).toString(),QString::fromUtf8("Slutstation Tjernobyl"));
QCOMPARE(m_info.track(13).get(Artist).toString(),QString::fromUtf8("SBD"));
QCOMPARE(m_info.track(14).get(Artist).toString(),QString::fromUtf8("Skumdum"));
QCOMPARE(m_info.track(15).get(Artist).toString(),QString::fromUtf8("Text"));
QCOMPARE(m_info.track(16).get(Artist).toString(),QString::fromUtf8("Ohlson Har Semester Production"));
// comments not supported in a simple way
for (int j=0; j < 17; j++)
QCOMPARE(m_info.track(j).get(Comment).toString(),QString());
// Make sure it's the same when loaded from the cache again
client_->config().setCacheLookupEnabled(true);
client_->config().setFreedbLookupEnabled(false);
client_->config().setMusicBrainzLookupEnabled(false);
client_->setBlockingMode(true);
client_->lookup(list);
CDInfoList response = client_->lookupResponse();
QVERIFY(response.count() > 0);
CDInfo cacheInfo(response.first());
QCOMPARE(m_info.get(Artist).toString(),cacheInfo.get(Artist).toString());
QCOMPARE(m_info.get(Title).toString(),cacheInfo.get(Title).toString());
QCOMPARE(m_info.get(Year).toInt(),cacheInfo.get(Year).toInt());
for (int j=0; j < 17; j++)
{
QCOMPARE(m_info.track(j).get(Title).toString(),cacheInfo.track(j).get(Title).toString());
QCOMPARE(m_info.track(j).get(Comment).toString(),cacheInfo.track(j).get(Comment).toString());
}
}
void
AsyncMusicBrainzTest::slotFinished(Result r)
{
m_result = r;
kDebug() << ": Got " << KCDDB::resultToString(r);
CDInfoList l = client_->lookupResponse();
kDebug() << ": Item count: " << l.count();
QVERIFY(l.count() > 0);
m_info = l.first();
m_eventLoop.quit();
}
QTEST_KDEMAIN(AsyncMusicBrainzTest, NoGUI)
#include "moc_asyncmusicbrainztest.cpp"

View file

@ -0,0 +1,45 @@
/*
Copyright (C) 2006 Richard Lärkäng <nouseforaname@home.se>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#ifndef TEST_H
#define TEST_H
#include <QEventLoop>
#include <QObject>
#include <libkcddb/client.h>
#include <libkcddb/kcddb.h>
using namespace KCDDB;
class AsyncMusicBrainzTest : public QObject
{
Q_OBJECT
private slots:
void testLookup();
void slotFinished(KCDDB::Result);
private:
QEventLoop m_eventLoop;
KCDDB::Client * client_;
CDInfo m_info;
Result m_result;
};
#endif

View file

@ -0,0 +1,88 @@
/*
Copyright (C) 2006 Richard Lärkäng <nouseforaname@home.se>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#include <kdebug.h>
#include <kapplication.h>
#include <kcmdlineargs.h>
#include "asyncsmtpsubmittest.h"
#include "libkcddb/submit.h"
AsyncSMTPSubmitTest::AsyncSMTPSubmitTest()
: QObject()
{
using namespace KCDDB;
client_ = new Client;
client_->config().setFreedbSubmitTransport(Submit::SMTP);
client_->config().setSubmitAddress("test-submit@freedb.org");
client_->setBlockingMode( false );
TrackOffsetList list;
list
<< 150 // First track start.
<< 2592
<< 35472
<< 47891
<< 123310
<< 133125; // Disc end.
CDInfo cdInfo;
cdInfo.set("discid", "3606ed05");
cdInfo.set("revision", 4);
cdInfo.set("title", "Bamse och Bronto");
cdInfo.set("artist", "Musiksage");
cdInfo.set("year", 2001);
cdInfo.set("category", "misc");
cdInfo.set("genre", "Barnsaga");
cdInfo.set("extd", QString::fromUtf8("Berättare: Olof Thunberg"));
cdInfo.track(0).set("title", "Bamses signaturmelodi");
cdInfo.track(1).set("title","*");
cdInfo.track(2).set("title", "Brummavisan");
cdInfo.track(3).set("title", "*");
cdInfo.track(4).set("title", QString::fromUtf8("Jätteödlan Bronto"));
connect(client_,SIGNAL(finished(KCDDB::Result)),SLOT(slotFinished(KCDDB::Result)));
client_->submit(cdInfo, list);
}
void
AsyncSMTPSubmitTest::slotFinished(Result r)
{
kDebug() << "AsyncSMTPSubmitTest::slotFinished: Got " << KCDDB::resultToString(r);
kapp->quit();
}
int main(int argc, char ** argv)
{
KCmdLineArgs::init(argc, argv, "libkcddb_test", 0, KLocalizedString(), "");
KApplication app(false);
new AsyncSMTPSubmitTest;
return app.exec();
}
#include "moc_asyncsmtpsubmittest.cpp"

View file

@ -0,0 +1,44 @@
/*
Copyright (C) 2003 Richard Lärkäng <nouseforaname@home.se>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#ifndef TEST_H
#define TEST_H
#include <QObject>
#include <libkcddb/client.h>
using namespace KCDDB;
class AsyncSMTPSubmitTest : public QObject
{
Q_OBJECT
public:
AsyncSMTPSubmitTest();
public slots:
void slotFinished(KCDDB::Result);
private:
KCDDB::Client * client_;
};
#endif

134
libkcddb/test/cachetest.cpp Normal file
View file

@ -0,0 +1,134 @@
/*
Copyright (C) 2007 Richard Lärkäng <nouseforaname@home.se>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#include "cachetest.h"
#include "libkcddb/cache.h"
#include <qtest_kde.h>
#include "libkcddb/cdinfo.h"
#include "libkcddb/client.h"
#include "config-musicbrainz.h"
using namespace KCDDB;
void CacheTest::initTestCase()
{
m_client = new Client;
m_client->config().setCacheLocations(QStringList(QDir::homePath()+"/.cddbTest/"));
// a1107d0a
m_list
<< 150 // First track start.
<< 29462
<< 66983
<< 96785
<< 135628
<< 168676
<< 194147
<< 222158
<< 247076
<< 278203 // Last track start.
<< 316732; // Disc end.
m_info.set(Artist, QString().leftJustified(10, QChar(0xe4)));
m_info.set(Title, QString().leftJustified(10, QChar(0xf6)));
for (int i=0; i<10; i++)
{
m_info.track(i).set(Title, QString().leftJustified(30*(i+1), 'a'+i));
}
}
void CacheTest::cleanupTestCase()
{
QDir().rmdir(QDir::homePath()+"/.cddbTest/");
}
bool CacheTest::verify(const QString& source, const QString& discid, const CDInfo& info)
{
Cache::store(m_list, info, m_client->config());
CDInfoList results = Cache::lookup(m_list, m_client->config());
foreach(const CDInfo &newInfo, results)
{
if (newInfo.get("source") == source && newInfo.get("discid").toString() == discid)
{
if (newInfo.get(Artist) != m_info.get(Artist))
continue;
if (newInfo.get(Title) != m_info.get(Title))
continue;
bool tracksOk = true;
for (int i=0; i < 10; i++)
{
if (newInfo.track(i).get(Title) != m_info.track(i).get(Title))
{
tracksOk = false;
break;
}
}
if (tracksOk)
return true;
}
}
return false;
}
void CacheTest::testFreedb()
{
CDInfo testInfo = m_info;
testInfo.set("source", "freedb");
testInfo.set("discid", "a1107d0a");
testInfo.set("category", "misc");
QVERIFY(verify("freedb", "a1107d0a", testInfo));
QFile::remove(QDir::homePath()+"/.cddbTest/misc/a1107d0a");
QDir().rmdir(QDir::homePath()+"/.cddbTest/misc/");
}
void CacheTest::testUser()
{
CDInfo testInfo = m_info;
testInfo.set("source", "user");
QVERIFY(verify("user", "a1107d0a", testInfo));
QFile::remove(QDir::homePath()+"/.cddbTest/user/a1107d0a");
QDir().rmdir(QDir::homePath()+"/.cddbTest/user/");
}
void CacheTest::testMusicbrainz()
{
#ifdef HAVE_MUSICBRAINZ5
CDInfo testInfo = m_info;
testInfo.set("source", "musicbrainz");
testInfo.set("discid", "wdABQ7s86gS7eVmS74CCQ6KwPUI-");
QVERIFY(verify("musicbrainz", "wdABQ7s86gS7eVmS74CCQ6KwPUI-", testInfo));
QFile::remove(QDir::homePath()+"/.cddbTest/musicbrainz/wdABQ7s86gS7eVmS74CCQ6KwPUI-");
QDir().rmdir(QDir::homePath()+"/.cddbTest/musicbrainz/");
#endif
}
QTEST_KDEMAIN(CacheTest, NoGUI)
#include "moc_cachetest.cpp"

50
libkcddb/test/cachetest.h Normal file
View file

@ -0,0 +1,50 @@
/*
Copyright (C) 2007 Richard Lärkäng <nouseforaname@home.se>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#ifndef CACHETEST_H
#define CACHETEST_H
#include "libkcddb/cdinfo.h"
#include "libkcddb/kcddb.h"
namespace KCDDB
{
class Client;
}
#include <QObject>
class CacheTest : public QObject
{
Q_OBJECT
private slots:
void initTestCase();
void cleanupTestCase();
void testFreedb();
void testUser();
void testMusicbrainz();
private:
bool verify(const QString& source, const QString& discid, const KCDDB::CDInfo& info);
KCDDB::Client* m_client;
KCDDB::CDInfo m_info;
KCDDB::TrackOffsetList m_list;
};
#endif

View file

@ -0,0 +1,93 @@
/*
Copyright (C) 2005-2006 Richard Lärkäng <nouseforaname@home.se>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#include <QtTest/QtTest>
#include <QtCore/QCoreApplication>
#include "libkcddb/cdinfo.h"
#include "cdinfotest.h"
using namespace KCDDB;
void CDInfoTest::testLongLines()
{
CDInfo info;
QString str;
TrackInfo& tinfo = info.track(0);
for (int i=0; i <= 100; i++)
{
str.fill('A',10*i);
info.set(Title, str);
str.fill('B',10*i);
str.append('\n');
info.set(Comment, str);
str.fill('C',10*i);
info.set(Artist, str);
str.fill('D',10*i);
info.set(Genre, str);
str.fill('E',10*i);
info.set(Length, str);
str.fill('F',10*i);
str.append('\n');
info.set("custom", str);
str.fill('G',10*i);
tinfo.set(Title, str);
str.fill('H',10*i);
str.append('\n');
tinfo.set("custom", str);
QString data = info.toString();
QString submitData = info.toString(true);
CDInfo info2;
info2.load(data);
str.fill('A',10*i);
QCOMPARE(info2.get(Title).toString(), str);
str.fill('B',10*i);
str.append('\n');
QCOMPARE(info2.get(Comment).toString(), str);
str.fill('C',10*i);
QCOMPARE(info2.get(Artist).toString(), str);
str.fill('D',10*i);
if (i == 0)
QCOMPARE(info2.get(Genre).toString(), QString("Unknown"));
else
QCOMPARE(info2.get(Genre).toString(), str);
str.fill('E',10*i);
QCOMPARE(info2.get(Length).toString(), str);
str.fill('F',10*i);
str.append('\n');
QCOMPARE(info2.get("custom").toString(), str);
str.fill('G',10*i);
QCOMPARE(info2.track(0).get(Title).toString(), str);
const CDInfo info3(info2);
QCOMPARE(info3.track(0).get(Title).toString(), str);
str.fill('H',10*i);
str.append('\n');
QCOMPARE(info2.track(0).get("custom").toString(), str);
QVERIFY(!submitData.contains("CUSTOM"));
QVERIFY(data.contains("CUSTOM"));
}
}
QTEST_MAIN(CDInfoTest)
#include "moc_cdinfotest.cpp"

View file

@ -0,0 +1,32 @@
/*
Copyright (C) 2005 Richard Lärkäng <nouseforaname@home.se>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#ifndef CDINFOTEST_H
#define CDINFOTEST_H
#include <QObject>
class CDInfoTest : public QObject
{
Q_OBJECT
private slots:
void testLongLines();
};
#endif

View file

@ -0,0 +1,157 @@
/*
Copyright (C) 2006 Richard Lärkäng <nouseforaname@home.se>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#include <qtest_kde.h>
#include "musicbrainztest-fulldate.h"
#include "libkcddb/client.h"
#include "libkcddb/cache.h"
#include "libkcddb/lookup.h"
#include "config-musicbrainz.h"
void MusicBrainzTestFullDate::testLookup()
{
using namespace KCDDB;
#ifndef HAVE_MUSICBRAINZ5
QSKIP("This test requires libmusicbrainz", SkipAll);
#endif
Client c;
c.config().setCacheLookupEnabled(false);
c.config().setFreedbLookupEnabled(false);
c.config().setMusicBrainzLookupEnabled(true);
TrackOffsetList list;
list <<
150 <<
11837 <<
20687 <<
29120 <<
35557 <<
50087 <<
58550 <<
72575 <<
81887 <<
95745 <<
104340 <<
115425 <<
124285 <<
132317 <<
142692 <<
160272 <<
169325 <<
181377 <<
194482 <<
205747 <<
216492 <<
229507 <<
242715 <<
252112 <<
274965 <<
285820 <<
308957 <<
322362 <<
338662 <<
350172 <<
356692;
Result r = c.lookup(list);
QVERIFY(r == Success);
kDebug() << "Client::lookup gave : " << resultToString(r);
CDInfoList response = c.lookupResponse();
kDebug() << "Client::lookup returned : " << response.count() << " entries"
<< endl;
QVERIFY(response.count() > 0);
// See http://musicbrainz.org/release/04319e80-0948-4e89-8180-7cf6f17fc77a for changes
CDInfo i(response.first());
QCOMPARE(i.numberOfTracks(),30);
QCOMPARE(i.get(Artist).toString(),QString("Troublemakers"));
QCOMPARE(i.get(Title).toString(),QString("30"));
// genre not really supported for musicbrainz
QCOMPARE(i.get(Genre).toString(),QString());
QCOMPARE(i.get(Year).toInt(),2011);
QCOMPARE(i.track(0).get(Title).toString(),QString("30"));
QCOMPARE(i.track(1).get(Title).toString(),QString::fromUtf8("Staden Göteborg"));
QCOMPARE(i.track(2).get(Title).toString(),QString::fromUtf8("Lilla Blå"));
QCOMPARE(i.track(3).get(Title).toString(),QString("Kleptoman"));
QCOMPARE(i.track(4).get(Title).toString(),QString::fromUtf8("Grogg å parabol"));
QCOMPARE(i.track(5).get(Title).toString(),QString("Majorna brinner"));
QCOMPARE(i.track(6).get(Title).toString(),QString::fromUtf8("Utan hjärta stannar Sverige"));
QCOMPARE(i.track(7).get(Title).toString(),QString("Dom e efter mig"));
QCOMPARE(i.track(8).get(Title).toString(),QString("Mammas flickor"));
QCOMPARE(i.track(9).get(Title).toString(),QString("Handgranat"));
QCOMPARE(i.track(10).get(Title).toString(),QString("Stenar o blod"));
QCOMPARE(i.track(11).get(Title).toString(),QString("Enkel Berlin"));
QCOMPARE(i.track(12).get(Title).toString(),QString("Dom ljuger"));
QCOMPARE(i.track(13).get(Title).toString(),QString("Jobba"));
QCOMPARE(i.track(14).get(Title).toString(),QString::fromUtf8("Varför lyser inga stjärnor"));
QCOMPARE(i.track(15).get(Title).toString(),QString("Partytrash"));
QCOMPARE(i.track(16).get(Title).toString(),QString::fromUtf8("Förstod ingenting"));
QCOMPARE(i.track(17).get(Title).toString(),QString::fromUtf8("Bara om min älskade väntar"));
QCOMPARE(i.track(18).get(Title).toString(),QString("Lillebror"));
QCOMPARE(i.track(19).get(Title).toString(),QString("Skandaler"));
QCOMPARE(i.track(20).get(Title).toString(),QString::fromUtf8("Hjältarna skålar i blod"));
QCOMPARE(i.track(21).get(Title).toString(),QString("Bomber o granater"));
QCOMPARE(i.track(22).get(Title).toString(),QString::fromUtf8("Vill du bli miljonär"));
QCOMPARE(i.track(23).get(Title).toString(),QString::fromUtf8("Stjärnorna kvittar det lika"));
QCOMPARE(i.track(24).get(Title).toString(),QString("Naken"));
QCOMPARE(i.track(25).get(Title).toString(),QString::fromUtf8("Månen lyser klar"));
QCOMPARE(i.track(26).get(Title).toString(),QString("Vild o vacker"));
QCOMPARE(i.track(27).get(Title).toString(),QString("Jag fryser"));
QCOMPARE(i.track(28).get(Title).toString(),QString("Ein zwei polizei"));
QCOMPARE(i.track(29).get(Title).toString(),QString::fromUtf8("Jävla idiot"));
for (int j=0; j < 30; j++)
QCOMPARE(i.track(j).get(Artist).toString(),QString("Troublemakers"));
// comments not supported in a simple way
for (int j=0; j < 19; j++)
QCOMPARE(i.track(j).get(Comment).toString(),QString());
// Make sure it's the same when loaded from the cache again
c.config().setCacheLookupEnabled(true);
c.config().setFreedbLookupEnabled(false);
c.config().setMusicBrainzLookupEnabled(false);
c.lookup(list);
response = c.lookupResponse();
QVERIFY(response.count() > 0);
CDInfo cacheInfo(response.first());
QCOMPARE(i.get(Artist).toString(),cacheInfo.get(Artist).toString());
QCOMPARE(i.get(Title).toString(),cacheInfo.get(Title).toString());
QCOMPARE(i.get(Year).toInt(),cacheInfo.get(Year).toInt());
for (int j=0; j < 19; j++)
{
QCOMPARE(i.track(j).get(Title).toString(),cacheInfo.track(j).get(Title).toString());
QCOMPARE(i.track(j).get(Comment).toString(),cacheInfo.track(j).get(Comment).toString());
}
}
QTEST_KDEMAIN(MusicBrainzTestFullDate, NoGUI)
#include "moc_musicbrainztest-fulldate.cpp"

View file

@ -0,0 +1,32 @@
/*
Copyright (C) 2006 Richard Lärkäng <nouseforaname@home.se>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#ifndef MUSICBRAINZTESTFULLDATE_H
#define MUSICBRAINZTESTFULLDATE_H
#include <QObject>
class MusicBrainzTestFullDate : public QObject
{
Q_OBJECT
private slots:
void testLookup();
};
#endif

View file

@ -0,0 +1,141 @@
/*
Copyright (C) 2006 Richard Lärkäng <nouseforaname@home.se>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#include <qtest_kde.h>
#include "musicbrainztest-severaldiscs.h"
#include "libkcddb/client.h"
#include "libkcddb/cache.h"
#include "libkcddb/lookup.h"
#include "config-musicbrainz.h"
void MusicBrainzTestSeveralDiscs::testLookup()
{
using namespace KCDDB;
#ifndef HAVE_MUSICBRAINZ5
QSKIP("This test requires libmusicbrainz", SkipAll);
#endif
Client c;
c.config().setCacheLookupEnabled(false);
c.config().setFreedbLookupEnabled(false);
c.config().setMusicBrainzLookupEnabled(true);
TrackOffsetList list;
list <<
150 <<
17272 <<
36395 <<
47954 <<
63638 <<
77928 <<
95029 <<
112094 <<
130540 <<
145938 <<
160463 <<
180364 <<
195549 <<
203821 <<
222410 <<
230367 <<
249241 <<
273944 <<
287584 <<
309904 <<
325124;
Result r = c.lookup(list);
QVERIFY(r == Success);
kDebug() << "Client::lookup gave : " << resultToString(r);
CDInfoList response = c.lookupResponse();
kDebug() << "Client::lookup returned : " << response.count() << " entries"
<< endl;
QVERIFY(response.count() > 0);
// See http://musicbrainz.org/release/4e0655b5-22fc-496e-9c14-2ee1a6027b45 for changes (disc 2)
CDInfo i(response.first());
QCOMPARE(i.numberOfTracks(),20);
QCOMPARE(i.get(Artist).toString(),QString("Billy Bragg"));
QCOMPARE(i.get(Title).toString(),QString("Must I Paint You a Picture? The Essential Billy Bragg (disc 2)"));
// genre not really supported for musicbrainz
QCOMPARE(i.get(Genre).toString(),QString());
QCOMPARE(i.get(Year).toInt(),2003);
QCOMPARE(i.track(0).get(Title).toString(),QString("Sexuality"));
QCOMPARE(i.track(1).get(Title).toString(),QString("Cindy of 1000 Lives"));
QCOMPARE(i.track(2).get(Title).toString(),QString("Moving the Goalposts"));
QCOMPARE(i.track(3).get(Title).toString(),QString("Tank Park Salute"));
QCOMPARE(i.track(4).get(Title).toString(),QString("You Woke Up My Neighbourhood"));
QCOMPARE(i.track(5).get(Title).toString(),QString("Accident Waiting to Happen (Red Stars version)"));
QCOMPARE(i.track(6).get(Title).toString(),QString("Sulk"));
QCOMPARE(i.track(7).get(Title).toString(),QString("Upfield"));
QCOMPARE(i.track(8).get(Title).toString(),QString("The Fourteenth of February"));
QCOMPARE(i.track(9).get(Title).toString(),QString("Brickbat"));
QCOMPARE(i.track(10).get(Title).toString(),QString("The Space Race Is Over"));
QCOMPARE(i.track(11).get(Title).toString(),QString("The Boy Done Good"));
QCOMPARE(i.track(12).get(Title).toString(),QString("Ingrid Bergman"));
QCOMPARE(i.track(13).get(Title).toString(),QString("Way Over Yonder in the Minor Key"));
QCOMPARE(i.track(14).get(Title).toString(),QString("My Flying Saucer"));
QCOMPARE(i.track(15).get(Title).toString(),QString("All You Fascists Bound to Lose (Blokes version)"));
QCOMPARE(i.track(16).get(Title).toString(),QString("NPWA"));
QCOMPARE(i.track(17).get(Title).toString(),QString("St. Monday"));
QCOMPARE(i.track(18).get(Title).toString(),QString("Somedays I See the Point"));
QCOMPARE(i.track(19).get(Title).toString(),QString("Take Down the Union Jack (Band version)"));
for (int j=0; j < 12; j++)
QCOMPARE(i.track(j).get(Artist).toString(),QString("Billy Bragg"));
for (int j=12; j < 15; j++)
QCOMPARE(i.track(j).get(Artist).toString(),QString("Billy Bragg & Wilco"));
for (int j=15; j < 20; j++)
QCOMPARE(i.track(j).get(Artist).toString(),QString("Billy Bragg and The Blokes"));
// comments not supported in a simple way
for (int j=0; j < 19; j++)
QCOMPARE(i.track(j).get(Comment).toString(),QString());
// Make sure it's the same when loaded from the cache again
c.config().setCacheLookupEnabled(true);
c.config().setFreedbLookupEnabled(false);
c.config().setMusicBrainzLookupEnabled(false);
c.lookup(list);
response = c.lookupResponse();
QVERIFY(response.count() > 0);
CDInfo cacheInfo(response.first());
QCOMPARE(i.get(Artist).toString(),cacheInfo.get(Artist).toString());
QCOMPARE(i.get(Title).toString(),cacheInfo.get(Title).toString());
QCOMPARE(i.get(Year).toInt(),cacheInfo.get(Year).toInt());
for (int j=0; j < 19; j++)
{
QCOMPARE(i.track(j).get(Title).toString(),cacheInfo.track(j).get(Title).toString());
QCOMPARE(i.track(j).get(Comment).toString(),cacheInfo.track(j).get(Comment).toString());
}
}
QTEST_KDEMAIN(MusicBrainzTestSeveralDiscs, NoGUI)
#include "moc_musicbrainztest-severaldiscs.cpp"

View file

@ -0,0 +1,32 @@
/*
Copyright (C) 2006 Richard Lärkäng <nouseforaname@home.se>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#ifndef MUSICBRAINZTESTSEVERALDISCS_H
#define MUSICBRAINZTESTSEVERALDISCS_H
#include <QObject>
class MusicBrainzTestSeveralDiscs : public QObject
{
Q_OBJECT
private slots:
void testLookup();
};
#endif

View file

@ -0,0 +1,124 @@
/*
Copyright (C) 2006 Richard Lärkäng <nouseforaname@home.se>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#include <qtest_kde.h>
#include "musicbrainztest.h"
#include "libkcddb/client.h"
#include "libkcddb/cache.h"
#include "libkcddb/lookup.h"
#include "config-musicbrainz.h"
void MusicBrainzTest::testLookup()
{
using namespace KCDDB;
#ifndef HAVE_MUSICBRAINZ5
QSKIP("This test requires libmusicbrainz", SkipAll);
#endif
Client c;
c.config().setCacheLookupEnabled(false);
c.config().setFreedbLookupEnabled(false);
c.config().setMusicBrainzLookupEnabled(true);
TrackOffsetList list;
//The Liptones / The Latest News
list
<< 150
<< 9219
<< 20386
<< 34134
<< 51437
<< 68809
<< 86591
<< 106288
<< 115568
<< 133312
<< 155593
<< 169832
<< 179626
<< 194958
<< 212506;
Result r = c.lookup(list);
QVERIFY(r == Success);
kDebug() << "Client::lookup gave : " << resultToString(r);
CDInfoList response = c.lookupResponse();
kDebug() << "Client::lookup returned : " << response.count() << " entries"
<< endl;
QVERIFY(response.count() > 0);
// See http://musicbrainz.org/release/68ec4a09-576c-472e-9103-aed99b6a3ffc for changes
CDInfo i(response.first());
QCOMPARE(i.numberOfTracks(),14);
QCOMPARE(i.get(Artist).toString(),QString("The Liptones"));
QCOMPARE(i.get(Title).toString(),QString("The Latest News"));
// genre not really supported for musicbrainz
QCOMPARE(i.get(Genre).toString(),QString());
QCOMPARE(i.get(Year).toInt(),2002);
QCOMPARE(i.track(0).get(Title).toString(),QString("Jungle Heat"));
QCOMPARE(i.track(1).get(Title).toString(),QString("It's All I Hear You Say"));
QCOMPARE(i.track(2).get(Title).toString(),QString("Girl for Tonight"));
QCOMPARE(i.track(3).get(Title).toString(),QString("Shoot Em Down"));
QCOMPARE(i.track(4).get(Title).toString(),QString("Beautiful Day"));
QCOMPARE(i.track(5).get(Title).toString(),QString("Paranoia"));
QCOMPARE(i.track(6).get(Title).toString(),QString("My Way"));
QCOMPARE(i.track(7).get(Title).toString(),QString("Dressed in Pink"));
QCOMPARE(i.track(8).get(Title).toString(),QString("No Way Out"));
QCOMPARE(i.track(9).get(Title).toString(),QString("Strange Kind of Justice"));
QCOMPARE(i.track(10).get(Title).toString(),QString("Waiting Til Midnight"));
QCOMPARE(i.track(11).get(Title).toString(),QString("Liptones"));
QCOMPARE(i.track(12).get(Title).toString(),QString("Out With the Boys"));
QCOMPARE(i.track(13).get(Title).toString(),QString("Free Like a Bird"));
// comments not supported in a simple way
for (int j=0; j < 14; j++)
QCOMPARE(i.track(j).get(Comment).toString(),QString());
// Make sure it's the same when loaded from the cache again
c.config().setCacheLookupEnabled(true);
c.config().setFreedbLookupEnabled(false);
c.config().setMusicBrainzLookupEnabled(false);
c.lookup(list);
response = c.lookupResponse();
QVERIFY(response.count() > 0);
CDInfo cacheInfo(response.first());
QCOMPARE(i.get(Artist).toString(),cacheInfo.get(Artist).toString());
QCOMPARE(i.get(Title).toString(),cacheInfo.get(Title).toString());
QCOMPARE(i.get(Year).toInt(),cacheInfo.get(Year).toInt());
for (int j=0; j < 14; j++)
{
QCOMPARE(i.track(j).get(Title).toString(),cacheInfo.track(j).get(Title).toString());
QCOMPARE(i.track(j).get(Comment).toString(),cacheInfo.track(j).get(Comment).toString());
}
}
QTEST_KDEMAIN(MusicBrainzTest, NoGUI)
#include "moc_musicbrainztest.cpp"

View file

@ -0,0 +1,32 @@
/*
Copyright (C) 2006 Richard Lärkäng <nouseforaname@home.se>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#ifndef MUSICBRAINZTEST_H
#define MUSICBRAINZTEST_H
#include <QObject>
class MusicBrainzTest : public QObject
{
Q_OBJECT
private slots:
void testLookup();
};
#endif

View file

@ -0,0 +1,48 @@
/*
Copyright (C) 2003 Richard Lärkäng <nouseforaname@home.se>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#include <kdebug.h>
#include <kapplication.h>
#include <kcmdlineargs.h>
#include "libkcddb/sites.h"
#include <qlist.h>
int
main(int argc, char ** argv)
{
KCmdLineArgs::init(argc, argv, "libkcddb_test", 0, KLocalizedString(), "");
KApplication app(true);
using namespace KCDDB;
Sites s;
kDebug() << "Sites: ";
QList<Mirror> sites = s.siteList();
for (QList<Mirror>::Iterator it = sites.begin(); it != sites.end(); ++it)
if ((*it).transport == Lookup::CDDBP)
kDebug() << (*it).address << " CDDBP " << (*it).port << " " << (*it).description;
else
kDebug() << (*it).address << " HTTP " << (*it).port << " " << (*it).description;
return 0;
}

Some files were not shown because too many files have changed in this diff Show more