<commit_before>/****************************************************************************
 *   Copyright (C) 2012-2018 Savoir-faire Linux                          *
 *   Author : <NAME> <<EMAIL>> *
 *                                                                          *
 *   This library is free software; you can redistribute it and/or          *
 *   modify it under the terms of the GNU Lesser General Public             *
 *   License as published by the Free Software Foundation; either           *
 *   version 2.1 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      *
 *   Lesser General Public License for more details.                        *
 *                                                                          *
 *   You should have received a copy of the GNU General Public License      *
 *   along with this program.  If not, see <http://www.gnu.org/licenses/>.  *
 ***************************************************************************/
#include "device.h"

//Qt
#include <QtCore/QTimer>

//Ring
#include "../dbus/videomanager.h"
#include "devicemodel.h"
#include "resolution.h"
#include "rate.h"
#include "channel.h"
#include "renderer.h"
#include "previewmanager.h"

//Ring private
#include "../private/videochannel_p.h"
#include "../private/videodevice_p.h"
#include "../private/videorate_p.h"
#include "../private/videoresolution_p.h"
#include "../private/videorenderermanager.h"

VideoDevicePrivate::VideoDevicePrivate(Video::Device* parent) : QObject(parent),m_pCurrentChannel(nullptr),m_RequireSave(false),q_ptr(parent)
{
}

///Constructor
Video::Device::Device(const QString &id) : QAbstractListModel(nullptr),
d_ptr(new VideoDevicePrivate(this))
{
   d_ptr->m_DeviceId = id;
   VideoManagerInterface& interface = VideoManager::instance();
   MapStringMapStringVectorString cap = interface.getCapabilities(id);
   QMapIterator<QString, MapStringVectorString> channels(cap);
   while (channels.hasNext()) {
      channels.next();

      Video::Channel* chan = new Video::Channel(this,channels.key());
      d_ptr->m_lChannels << chan;
      QList<Video::Resolution*> validResolutions;

      QMapIterator<QString, VectorString> resolutions(channels.value());
      while (resolutions.hasNext()) {
         resolutions.next();

         Video::Resolution* res = new Video::Resolution(resolutions.key(),chan);
         validResolutions << res;

         foreach(const QString& rate, resolutions.value()) {
            Video::Rate* r = new Video::Rate(res,rate);
            res->d_ptr->m_lValidRates << r;
         }
      }

      // Sort resolutions by size area.
      qSort(validResolutions.begin(),
      validResolutions.end(),
      [](Video::Resolution* resA, Video::Resolution* resB) {
          return resA->width()  * resA->height() > resB->width() * resB->height();
      });
      chan->d_ptr->m_lValidResolutions = validResolutions;
   }
   Q_UNUSED(cap)
}

///Destructor
Video::Device::~Device()
{
//    delete d_ptr;
}<commit_msg>fix: sort and deduplicate frame rates<commit_after>/****************************************************************************
 *   Copyright (C) 2012-2018 Savoir-faire Linux                          *
 *   Author : <NAME> <<EMAIL>> *
 *                                                                          *
 *   This library is free software; you can redistribute it and/or          *
 *   modify it under the terms of the GNU Lesser General Public             *
 *   License as published by the Free Software Foundation; either           *
 *   version 2.1 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      *
 *   Lesser General Public License for more details.                        *
 *                                                                          *
 *   You should have received a copy of the GNU General Public License      *
 *   along with this program.  If not, see <http://www.gnu.org/licenses/>.  *
 ***************************************************************************/
#include "device.h"

//Qt
#include <QtCore/QTimer>

//Ring
#include "../dbus/videomanager.h"
#include "devicemodel.h"
#include "resolution.h"
#include "rate.h"
#include "channel.h"
#include "renderer.h"
#include "previewmanager.h"

//Ring private
#include "../private/videochannel_p.h"
#include "../private/videodevice_p.h"
#include "../private/videorate_p.h"
#include "../private/videoresolution_p.h"
#include "../private/videorenderermanager.h"

VideoDevicePrivate::VideoDevicePrivate(Video::Device* parent) : QObject(parent),m_pCurrentChannel(nullptr),m_RequireSave(false),q_ptr(parent)
{
}

///Constructor
Video::Device::Device(const QString &id) : QAbstractListModel(nullptr),
d_ptr(new VideoDevicePrivate(this))
{
   d_ptr->m_DeviceId = id;
   VideoManagerInterface& interface = VideoManager::instance();
   MapStringMapStringVectorString cap = interface.getCapabilities(id);
   QMapIterator<QString, MapStringVectorString> channels(cap);
   while (channels.hasNext()) {
      channels.next();

      Video::Channel* chan = new Video::Channel(this,channels.key());
      d_ptr->m_lChannels << chan;
      QList<Video::Resolution*> validResolutions;

      QMapIterator<QString, VectorString> resolutions(channels.value());
      while (resolutions.hasNext()) {
         resolutions.next();

         Video::Resolution* res = new Video::Resolution(resolutions.key(),chan);
         validResolutions << res;

         foreach(const QString& rate, resolutions.value()) {
            Video::Rate* r = new Video::Rate(res,rate);
            if (!res->d_ptr->m_lValidRates.contains(r)) {
                res->d_ptr->m_lValidRates << r;
            }
         }

         // Sort rates in increasing order.
         qSort(res->d_ptr->m_lValidRates.begin(),
         res->d_ptr->m_lValidRates.end(),
         [](Video::Rate* rateA, Video::Rate* rateB) {
             return rateA->name().toInt() > rateB->name().toInt();
         });
      }

      // Sort resolutions by size area.
      qSort(validResolutions.begin(),
      validResolutions.end(),
      [](Video::Resolution* resA, Video::Resolution* resB) {
          return resA->width()  * resA->height() > resB->width() * resB->height();
      });
      chan->d_ptr->m_lValidResolutions = validResolutions;
   }
   Q_UNUSED(cap)
}

///Destructor
Video::Device::~Device()
{
//    delete d_ptr;
}
{'fraction_non_alphanumeric': 0.16292054402290623, 'fraction_numerical': 0.002863278453829635, 'mean_word_length': 2.48428927680798, 'pattern_counts': {'":': 0, '<': 31, '<?xml version=': 0, '>': 50, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 18, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1836040', 'n_tokens_mistral': 1930, 'n_tokens_neox': 1877, 'n_words': 459}