/***************************************************************************
   This file is part of LinTV
   lintvglobal.cpp
   A static class containing global functions that both LinTV and LinTVScheduler
   can use.

   Author: Jesse L. Zamora <xtremek2009@gmail.com>

   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 "lintvglobal.h"

#include <kdebug.h>

QSize LinTVGlobal::largeVideoResolution = QSize(720, 480);
QSize LinTVGlobal::mediumVideoResolution = QSize(480, 480);
QSize LinTVGlobal::smallVideoResolution = QSize(352, 240);

VideoResolutions LinTVGlobal::defaultVideoResolutions;

QList<int> LinTVGlobal::audioBitrates;
QList<float> LinTVGlobal::videoFramerates;
QStringList LinTVGlobal::videoFormats;

VideoAudioParameters LinTVGlobal::Presets[NR_OF_PRESETS] = {
    { "VCD Standard Play", 1150, 0, 352, 240, "mp1", 29.97, 224, "mp2" },
    { "SVCD Long Play", 1600, 2000, 480, 480, "mp2", 29.97, 224, "mp2" },
    { "SVCD Standard Play", 2000, 2600, 480, 480, "mp2", 29.97, 256, "mp2" },
    { "DVD Extra Long Play", 3000, 4400, 720, 480, "mp2", 29.97,  256,"mp2" },
    { "DVD Long Play", 4800, 6200, 720, 480, "mp2", 29.97, 384, "ac3" },
    { "DVD Standard Play", 6400, 8000, 720, 480, "mp2", 29.97, 448,"ac3" },
    { "Custom", 0, 0, 0, 0, "", 0.0, 0, "" }
};

CountryVideoStandard LinTVGlobal::countryVideoStandards[] = {
    { "Abu Dhabi", PAL },
    { "Afghanistan", PAL },
    { "Alaska", NTSC },
    { "Albania", PAL },
    { "Algeria", PAL },
    { "American Samoa", NTSC },
    { "Andorra", SECAM },
    { "Angola", PAL },
    { "Antigua", NTSC },
    { "Antilles (Dutch)", NTSC },
    { "Argentina", PAL },
    { "Aruba", NTSC },
    { "Ascension Island", PAL },
    { "Australia", PAL },
    { "Austria", PAL },
    { "Azores", PAL },
    { "Azerbaijan", SECAM },
    
    { "Bahamas", NTSC },
    { "Baharin", PAL },
    { "Bangladesh", PAL },
    { "Barbados", NTSC },
    { "Barbuda", NTSC },
    { "Belarus", SECAM },
    { "Belgium", PAL },
    { "Belize", NTSC },
    { "Benin", SECAM },
    { "Bermuda", NTSC },
    { "Bolivia", NTSC },
    { "Bosnia Herzegovinia", PAL },
    { "Botswana", PAL },
    { "Brazil", PAL },
    { "British Virgin Islands", NTSC },
    { "Brunei", PAL },
    { "Bulgaria", SECAM },
    { "Burkina Faso", SECAM },
    { "Burma", NTSC },
    { "Burundi", SECAM },
      
    { "Cambodia (Kampuchea)", SECAM },
    { "Cameroon", PAL },
    { "Canada", NTSC },
    { "Canary Islands", PAL },
    { "Cape Verde", PAL },
    { "Caymen Islands", PAL },
    { "Central African Republic", SECAM },
    { "Chad", SECAM },
    { "Chile", NTSC },
    { "China (Peoples Republic)", PAL },
    { "Christmas Island", PAL },
    { "Columbia", NTSC },
    { "Congo (Peoples Republic)", SECAM },
    { "Cook Island", PAL },
    { "Corsica", SECAM },
    { "Costa Rica", NTSC },
    { "Cuba", NTSC },
    { "Curacao", NTSC },
    { "Cyrpus", PAL },
    { "Cyprus (Turkish)", PAL },
    { "Czech Republic (Nova)", SECAM },
    { "Czech Republic", PAL },
    
    { "Dahomey", SECAM },
    { "Denmark", PAL },
    { "Deigo Garcia", NTSC },
    { "Djibouti", NTSC },
    { "Dominica", NTSC },
    { "Dominican Republic", NTSC },
    { "Dubai", PAL },

    { "Easter Island", PAL },
    { "Ecuador", NTSC },
    { "Egypt", SECAM },
    { "El Salvador", NTSC },
    { "Equatorial Guinea", SECAM },
    { "Eritrea", PAL },
    { "Estonia", SECAM },
    { "Ethiopia", PAL },

    { "Falkland Islands", PAL },
    { "Faroe Islands", PAL },
    { "Fiji", PAL },
    { "Finland", PAL },
    { "France", SECAM },

    { "Gabon", SECAM },
    { "Galapagos Island", NTSC },
    { "Gambia", PAL },
    { "Gaza & West Bank", PAL },
    { "Georgia", SECAM },
    { "Germany", PAL },
    { "Ghana", PAL },
    { "Gibraltar", PAL },
    { "Greece", SECAM },
    { "Greenland", NTSC },
    { "Grenada", NTSC },
    { "Guadeloupe", SECAM },
    { "Guam", NTSC },
    { "Guatemala", NTSC },
    { "Guinea", PAL },
    { "Guinea-Bissau", PAL },
    { "Guyana (French)", SECAM },
    { "Guyana Republic", NTSC },

    { "Haiti", NTSC },
    { "Hawaii", NTSC },
    { "Holland", PAL },
    { "Honduras", NTSC },
    { "Hong Kong", PAL },
    { "Hungary", SECAM },
    
    { "Iceland", PAL },
    { "India", PAL },
    { "Indonesia", PAL },
    { "Iran", SECAM },
    { "Iraq", SECAM },
    { "Ireland", PAL },
    { "Israel", PAL },
    { "Italy", PAL },
    { "Ivory Coast", SECAM },

    { "Jamaica", NTSC },
    { "Japan", NTSC },
    { "Johnston Islands", NTSC },
    { "Jordan", PAL },
    
    { "Kampuchea", SECAM },
    { "Kazakhstan", SECAM },
    { "Keyna", PAL },
    { "Kiribati", PAL },
    { "Korea North", SECAM },
    { "Korea South", NTSC },
    { "Kuwait", PAL },
    { "Kyrgystan", SECAM },
    
    { "Laos", PAL },
    { "Latvia", PAL },
    { "Lebanon", PAL },
    { "Leeward Islands", NTSC },
    { "Lesotho", PAL },
    { "Liberia", PAL },
    { "Libyia", SECAM },
    { "Liechtenstein", PAL },
    { "Lithuania", PAL },
    { "Luxembourg", PAL },
    
    { "Macau", PAL },
    { "Macedonia", PAL },
    { "Madagascar", SECAM },
    { "Madeira", PAL },
    { "Malawi", PAL },
    { "Malaysia", PAL },
    { "Maldives", PAL },
    { "Mali", SECAM },
    { "Mariana Islands", NTSC },
    { "Malta", PAL },
    { "Marshall Islands", NTSC },
    { "Martinique", SECAM },
    { "Mauritania", SECAM },
    { "Mauritius", SECAM },
    { "Mexico", NTSC },
    { "Micronesia", NTSC },
    { "Midway Islands", NTSC },
    { "Monaco", SECAM },
    { "Montenegro", PAL },
    { "Mongolia", SECAM },
    { "Montserrat", NTSC },
    { "Morocco", SECAM },
    { "Mozambique", PAL },
    { "Myanmar", NTSC },

    { "Namibia", PAL },
    { "Nepal", PAL },
    { "Netherlands", PAL },
    { "New Caledonia", SECAM },
    { "New Zealand", PAL },
    { "Nicaragua", NTSC },
    { "Niger", SECAM },
    { "Nigeria", PAL },
    { "Norfolk Island", PAL },
    { "Norway", PAL },

    { "Okinawa", NTSC },
    { "Oman", PAL },
    
    { "Pakistan", PAL },
    { "Palau", NTSC },
    { "Panama", NTSC },
    { "Papua New Guinea", PAL },
    { "Paraguay", PAL },
    { "Peru", NTSC },
    { "Philippines", NTSC },
    { "Poland", PAL },
    { "Polynesia", SECAM },
    { "Portugal", PAL },
    { "Puerto Rico", NTSC },

    { "Quatar", PAL },
    
    { "Reunion", SECAM },
    { "Romania", SECAM },
    { "Russia", SECAM },
    { "Rwanda", SECAM },

    { "Samoa", NTSC },
    { "Sardinia", PAL },
    { "Saudi Arabia", SECAM },
    { "Senegal", SECAM },
    { "Serbia", PAL },
    { "Seychelles", PAL },
    { "Sierra Leone", PAL },
    { "Singapore", PAL },
    { "Slovakia Republic", PAL },
    { "Slovenia", PAL },
    { "Solomon Islands", PAL },
    { "Somalia", PAL },
    { "South Africa", PAL },
    { "Spain", PAL },
    { "Sri Lanka", PAL },
    { "St. Kitts and Nevis", NTSC },
    { "St. Lucia", NTSC },
    { "St. Pierre", SECAM },
    { "St. Vincent", NTSC },
    { "Sudan", PAL },
    { "Surinam", NTSC },
    { "Swaziland", PAL },
    { "Sweden", PAL },
    { "Switzerland", PAL },
    { "Syria", SECAM },

    { "Tahiti", SECAM },
    { "Tajikistan", SECAM },
    { "Taiwan", NTSC },
    { "Tanzania", PAL },
    { "Thailand", PAL },
    { "Togo", SECAM },
    { "Tonga", PAL },
    { "Trinidad & Tobago", NTSC },
    { "Tristian Da Cunah", PAL },
    { "Tunisia", SECAM },
    { "Turkey", PAL },
    { "Trukmenistan", SECAM },

    { "Ukraine", SECAM },
    { "Uganda", PAL },
    { "United Arab Emirates",  PAL },
    { "United Kingdom", PAL },
    { "Uruguay", PAL },
    { "United States", NTSC },
    { "Uzbekistan", SECAM },

    { "Vanuatu", PAL },
    { "Vatican City", PAL },
    { "Venezuela", NTSC },
    { "Vietnam", NTSC },
    { "Virgin Islands", NTSC },

    { "Wallis Island", SECAM },
    
    { "Yemen", PAL },
    { "Yugoslavia", PAL },
    
    { "Zaire", SECAM },
    { "Zambia", PAL },
    { "Zanzibar", PAL },
    { "Zimbabwe", PAL },
    { "", "" }
};

LinTVGlobal::LinTVGlobal()
{
    // Initialize the default resolutions...
    defaultVideoResolutions << largeVideoResolution;
    defaultVideoResolutions << mediumVideoResolution;
    defaultVideoResolutions << smallVideoResolution;

    audioBitrates << 32 << 64 << 96 << 128 << 196 << 224 << 256 << 384 << 448;
    videoFramerates << 15 << 20 << 25 << 29.97 << 30 << 35;
    videoFormats << "mp1" << "mp2" << "mp4" << "mjpeg" << "wmv";

    // This is gonna be big....all the video standards in the world!
}

bool LinTVGlobal::isDefaultResolution(QSize size)
{
    for (int i = 0; i < defaultVideoResolutions.size(); i++) {
        if (defaultVideoResolutions[i] == size) {
            return true;
        }
    }

    return false;
}

bool LinTVGlobal::isLargeResolution(int width, int height)
{
    if (width == largeVideoResolution.width() &&
        height == largeVideoResolution.height()) {
        return true;
    } 

    return false;
}

bool LinTVGlobal::isMediumResolution(int width, int height)
{
    if (width == mediumVideoResolution.width() &&
        height == mediumVideoResolution.height()) {
        return true;
    } 

    return false;
}

bool LinTVGlobal::isSmallResolution(int width, int height)
{
    if (width == smallVideoResolution.width() &&
        height == smallVideoResolution.height()) {
        return true;
    } 

    return false;
}

