KCDDB

submit.cpp
1/*
2 SPDX-FileCopyrightText: 2002 Rik Hemsley (rikkus) <rik@kde.org>
3 SPDX-FileCopyrightText: 2002 Benjamin Meyer <ben-devel@meyerhome.net>
4 SPDX-FileCopyrightText: 2003-2005 Richard Lärkäng <nouseforaname@home.se>
5
6 SPDX-License-Identifier: LGPL-2.0-or-later
7*/
8
9#include "submit.h"
10#include "logging.h"
11
12namespace KCDDB
13{
14 Submit::Submit()
15 : CDDB()
16 {
17 // Empty.
18 }
19
20 Submit::~Submit()
21 {
22 // Empty.
23 }
24
25 Result Submit::submit( CDInfo cdInfo, const TrackOffsetList& offsetList)
26 {
27 // If it was an inexact math from the server the discid might
28 // be different, so recalculate it
29 cdInfo.set(QLatin1String( "discid" ), trackOffsetListToId(offsetList));
30
31 makeDiskData( cdInfo, offsetList );
32
33 if (!validCategory(cdInfo.get(Category).toString()))
34 return InvalidCategory;
35
36 KIO::Job* job = createJob(cdInfo);
37
38 if (!job)
39 return UnknownError;
40
41 return runJob(job);
42 }
43
44 Result
45 Submit::parseWrite( const QString & line )
46 {
47 uint serverStatus = statusCode( line );
48
49 if ( 320 != serverStatus )
50 return ServerError;
51
52 return Success;
53 }
54
55 void Submit::makeDiskData( const CDInfo& cdInfo, const TrackOffsetList& offsetList )
56 {
57 unsigned numTracks = cdInfo.numberOfTracks();
58
59 diskData_ += QLatin1String( "# xmcd\n" );
60 diskData_ += QLatin1String( "#\n" );
61 diskData_ += QLatin1String( "# Track frame offsets:\n" );
62
63 for (uint i=0; i < numTracks; i++)
64 diskData_ += QString::fromLatin1("#\t%1\n").arg(offsetList[i]);
65
66 int l = offsetList[numTracks]/75;
67 diskData_ += QString::fromLatin1("# Disc length: %1 seconds\n").arg(l);
68
69 diskData_ += cdInfo.toString(true);
70
71 qCDebug(LIBKCDDB) << "diskData_ == " << diskData_;
72 }
73
74 bool Submit::validCategory( const QString& c )
75 {
76 QStringList validCategories;
77 validCategories << QLatin1String( "blues" ) << QLatin1String( "classical" ) << QLatin1String( "country" )
78 << QLatin1String( "data" ) << QLatin1String( "folk" ) << QLatin1String( "jazz" ) << QLatin1String( "misc" ) << QLatin1String( "newage" ) << QLatin1String( "reggae" )
79 << QLatin1String( "rock" ) << QLatin1String( "soundtrack" );
80
81 if (validCategories.contains(c))
82 return true;
83 else
84 return false;
85 }
86}
87
88// vim:tabstop=2:shiftwidth=2:expandtab:cinoptions=(s,U1,m1
QString arg(Args &&... args) const const
QString fromLatin1(QByteArrayView str)
bool contains(QLatin1StringView str, Qt::CaseSensitivity cs) const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 18 2024 12:17:48 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.