mirror of
https://gitlab.linphone.org/BC/public/linphone-desktop.git
synced 2026-01-19 04:18:08 +00:00
Implement DateTime to fix QML bugs on Javascript and daylights. (Windows was a failing case)
This commit is contained in:
parent
1b8b57664c
commit
19231ec29f
12 changed files with 657 additions and 71 deletions
|
|
@ -216,6 +216,9 @@ set(SOURCES
|
|||
src/components/other/colors/ColorListModel.cpp
|
||||
src/components/other/colors/ColorProxyModel.cpp
|
||||
src/components/other/colors/ImageColorsProxyModel.cpp
|
||||
src/components/other/date/LDate.cpp
|
||||
src/components/other/date/LDateTime.cpp
|
||||
src/components/other/date/LTime.cpp
|
||||
src/components/other/images/ImageModel.cpp
|
||||
src/components/other/images/ImageListModel.cpp
|
||||
src/components/other/images/ImageProxyModel.cpp
|
||||
|
|
@ -351,6 +354,9 @@ set(HEADERS
|
|||
src/components/other/colors/ColorListModel.hpp
|
||||
src/components/other/colors/ColorProxyModel.hpp
|
||||
src/components/other/colors/ImageColorsProxyModel.hpp
|
||||
src/components/other/date/LDate.hpp
|
||||
src/components/other/date/LDateTime.hpp
|
||||
src/components/other/date/LTime.hpp
|
||||
src/components/other/images/ImageModel.hpp
|
||||
src/components/other/images/ImageListModel.hpp
|
||||
src/components/other/images/ImageProxyModel.hpp
|
||||
|
|
|
|||
|
|
@ -653,12 +653,20 @@ void App::registerTypes () {
|
|||
qRegisterMetaType<QSharedPointer<ChatCallModel>>();
|
||||
qRegisterMetaType<QSharedPointer<ConferenceInfoModel>>();
|
||||
//qRegisterMetaType<std::shared_ptr<ChatEvent>>();
|
||||
|
||||
LinphoneEnums::registerMetaTypes();
|
||||
|
||||
registerType<AssistantModel>("AssistantModel");
|
||||
registerType<AuthenticationNotifier>("AuthenticationNotifier");
|
||||
registerType<CallsListProxyModel>("CallsListProxyModel");
|
||||
registerType<Camera>("Camera");
|
||||
registerType<LDate>("LDate");
|
||||
qRegisterMetaType<LDate*>();
|
||||
registerType<LDate>("LDateTime");
|
||||
qRegisterMetaType<LDateTime*>();
|
||||
registerType<LDate>("LTime");
|
||||
qRegisterMetaType<LTime*>();
|
||||
|
||||
registerType<ChatRoomProxyModel>("ChatRoomProxyModel");
|
||||
registerType<ConferenceHelperModel>("ConferenceHelperModel");
|
||||
registerType<ConferenceProxyModel>("ConferenceProxyModel");
|
||||
|
|
@ -753,6 +761,9 @@ void App::registerToolTypes () {
|
|||
qInfo() << QStringLiteral("Registering tool types...");
|
||||
|
||||
registerToolType<Clipboard>("Clipboard");
|
||||
registerToolType<LDate>("DateTools");
|
||||
registerToolType<LDateTime>("DateTimeTools");
|
||||
registerToolType<LTime>("TimeTools");
|
||||
registerToolType<DesktopTools>("DesktopTools");
|
||||
registerToolType<TextToSpeech>("TextToSpeech");
|
||||
registerToolType<Units>("Units");
|
||||
|
|
|
|||
|
|
@ -94,6 +94,9 @@
|
|||
#include "other/colors/ColorProxyModel.hpp"
|
||||
#include "other/colors/ImageColorsProxyModel.hpp"
|
||||
#include "other/clipboard/Clipboard.hpp"
|
||||
#include "other/date/LDate.hpp"
|
||||
#include "other/date/LDateTime.hpp"
|
||||
#include "other/date/LTime.hpp"
|
||||
#include "other/desktop-tools/DesktopTools.hpp"
|
||||
#include "other/images/ImageModel.hpp"
|
||||
#include "other/images/ImageListModel.hpp"
|
||||
|
|
|
|||
110
linphone-app/src/components/other/date/LDate.cpp
Normal file
110
linphone-app/src/components/other/date/LDate.cpp
Normal file
|
|
@ -0,0 +1,110 @@
|
|||
/*
|
||||
* Copyright (c) 2010-2022 Belledonne Communications SARL.
|
||||
*
|
||||
* This file is part of linphone-desktop
|
||||
* (see https://www.linphone.org).
|
||||
*
|
||||
* 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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "LDate.hpp"
|
||||
|
||||
#include "app/App.hpp"
|
||||
|
||||
#include <QLocale>
|
||||
|
||||
// =============================================================================
|
||||
|
||||
LDate::LDate(QObject *parent) : QObject(parent) {
|
||||
}
|
||||
LDate::LDate(const QDate& date, QObject *parent) : QObject(parent)
|
||||
, mDate(date){
|
||||
}
|
||||
LDate::LDate(const int& year, const int& month, const int& day, QObject *parent) : QObject(parent)
|
||||
, mDate(year, month, day){
|
||||
}
|
||||
|
||||
LDate * LDate::create(){
|
||||
return new LDate(QDate::currentDate());
|
||||
}
|
||||
|
||||
LDate * LDate::create(const QDateTime& dateTime){
|
||||
return new LDate(dateTime.date());
|
||||
}
|
||||
|
||||
LDate * LDate::create(const int& year, const int& month, const int& day){
|
||||
return new LDate(year, month, day);
|
||||
}
|
||||
|
||||
QString LDate::toDateString(const QString& format) const{
|
||||
if(format == "")
|
||||
return QLocale().toString(mDate, QLocale::ShortFormat);
|
||||
else
|
||||
return QLocale().toString(mDate,format);
|
||||
}
|
||||
|
||||
bool LDate::isToday() const{
|
||||
return mDate == QDate::currentDate();
|
||||
}
|
||||
|
||||
bool LDate::isFuture() const{
|
||||
return mDate > QDate::currentDate();
|
||||
}
|
||||
|
||||
bool LDate::isGreatherThan(LDate* date) const{
|
||||
return date && mDate >= date->mDate;
|
||||
}
|
||||
|
||||
bool LDate::isEqual(LDate* date) const{
|
||||
return date && mDate == date->mDate;
|
||||
}
|
||||
|
||||
QDate LDate::getDate()const{
|
||||
return mDate;
|
||||
}
|
||||
|
||||
int LDate::getDay()const{
|
||||
return mDate.day();
|
||||
}
|
||||
|
||||
int LDate::getWeekDay()const{
|
||||
return mDate.dayOfWeek();
|
||||
}
|
||||
|
||||
int LDate::getMonth()const{
|
||||
return mDate.month();
|
||||
}
|
||||
|
||||
int LDate::getYear()const{
|
||||
return mDate.year();
|
||||
}
|
||||
|
||||
void LDate::setDay(const int& data){
|
||||
if(getDay() != data){
|
||||
mDate = QDate(getYear(), getMonth(), data);
|
||||
emit dayChanged();
|
||||
}
|
||||
}
|
||||
void LDate::setMonth(const int& data){
|
||||
if(getMonth() != data){
|
||||
mDate = QDate(getYear(), data, getDay());
|
||||
emit monthChanged();
|
||||
}
|
||||
}
|
||||
void LDate::setYear(const int& data){
|
||||
if(getYear() != data){
|
||||
mDate = QDate(data, getMonth(), getDay());
|
||||
emit yearChanged();
|
||||
}
|
||||
}
|
||||
72
linphone-app/src/components/other/date/LDate.hpp
Normal file
72
linphone-app/src/components/other/date/LDate.hpp
Normal file
|
|
@ -0,0 +1,72 @@
|
|||
/*
|
||||
* Copyright (c) 2010-2022 Belledonne Communications SARL.
|
||||
*
|
||||
* This file is part of linphone-desktop
|
||||
* (see https://www.linphone.org).
|
||||
*
|
||||
* 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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#ifndef DATE_H_
|
||||
#define DATE_H_
|
||||
|
||||
// Used to replace QML Date because of Times bugs (local timezones that changes date)
|
||||
|
||||
#include <QObject>
|
||||
#include <QDate>
|
||||
// =============================================================================
|
||||
|
||||
class LDate : public QObject {
|
||||
Q_OBJECT
|
||||
public:
|
||||
Q_PROPERTY(int day READ getDay WRITE setDay NOTIFY dayChanged)
|
||||
Q_PROPERTY(int weekday READ getWeekDay NOTIFY dayChanged)
|
||||
Q_PROPERTY(int month READ getMonth WRITE setMonth NOTIFY monthChanged)
|
||||
Q_PROPERTY(int year READ getYear WRITE setYear NOTIFY yearChanged)
|
||||
|
||||
LDate (QObject *parent = Q_NULLPTR);
|
||||
LDate(const QDate& date, QObject *parent = Q_NULLPTR);
|
||||
LDate(const int& year, const int& month, const int& day, QObject *parent = Q_NULLPTR);
|
||||
|
||||
Q_INVOKABLE static LDate * create();
|
||||
Q_INVOKABLE static LDate * create(const QDateTime& dateTime);
|
||||
Q_INVOKABLE static LDate * create(const int& year, const int& month, const int& day);
|
||||
|
||||
Q_INVOKABLE QString toDateString(const QString& format = "") const;// Do not use toString as it's a conflict with JS toString()
|
||||
Q_INVOKABLE bool isToday() const;
|
||||
Q_INVOKABLE bool isFuture() const;
|
||||
Q_INVOKABLE bool isGreatherThan(LDate* date) const;
|
||||
Q_INVOKABLE bool isEqual(LDate* date) const;
|
||||
|
||||
QDate getDate()const;
|
||||
int getDay()const;
|
||||
int getWeekDay()const;
|
||||
int getMonth()const;
|
||||
int getYear()const;
|
||||
|
||||
void setDay(const int& data);
|
||||
void setMonth(const int& data);
|
||||
void setYear(const int& data);
|
||||
|
||||
signals:
|
||||
|
||||
void dayChanged();
|
||||
void monthChanged();
|
||||
void yearChanged();
|
||||
|
||||
private:
|
||||
QDate mDate;
|
||||
};
|
||||
Q_DECLARE_METATYPE(LDate*);
|
||||
|
||||
#endif
|
||||
144
linphone-app/src/components/other/date/LDateTime.cpp
Normal file
144
linphone-app/src/components/other/date/LDateTime.cpp
Normal file
|
|
@ -0,0 +1,144 @@
|
|||
/*
|
||||
* Copyright (c) 2010-2022 Belledonne Communications SARL.
|
||||
*
|
||||
* This file is part of linphone-desktop
|
||||
* (see https://www.linphone.org).
|
||||
*
|
||||
* 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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "LDateTime.hpp"
|
||||
|
||||
#include "LDate.hpp"
|
||||
#include "LTime.hpp"
|
||||
#include "app/App.hpp"
|
||||
|
||||
#include <QLocale>
|
||||
|
||||
// =============================================================================
|
||||
|
||||
LDateTime::LDateTime(QObject *parent) : QObject(parent) {
|
||||
}
|
||||
LDateTime::LDateTime(const QDateTime& dateTime, QObject *parent) : QObject(parent)
|
||||
, mDateTime(dateTime){
|
||||
}
|
||||
LDateTime::LDateTime(LDate * date, LTime * time, QObject *parent) : QObject(parent)
|
||||
, mDateTime(date->getDate(), time->getTime()){
|
||||
}
|
||||
LDateTime::LDateTime(const int& year, const int& month, const int& day, const int& hour, const int& minute, const int& second, QObject *parent) : QObject(parent)
|
||||
, mDateTime(QDate(year, month, day), QTime(hour, minute, second)){
|
||||
}
|
||||
|
||||
LDateTime * LDateTime::create(){
|
||||
return new LDateTime(QDateTime::currentDateTime());
|
||||
}
|
||||
|
||||
LDateTime * LDateTime::create(LDate * date, LTime * time){
|
||||
return new LDateTime(date, time);
|
||||
}
|
||||
|
||||
LDateTime * LDateTime::create(const int& year, const int& month, const int& day, const int& hour, const int& minute, const int& second){
|
||||
return new LDateTime(year, month, day, hour, minute, second);
|
||||
}
|
||||
|
||||
QString LDateTime::toDateTimeString(const QString& format) const{
|
||||
if(format == "")
|
||||
return QLocale().toString(mDateTime, QLocale::ShortFormat);
|
||||
else
|
||||
return QLocale().toString(mDateTime,format);
|
||||
}
|
||||
|
||||
bool LDateTime::isToday() const{
|
||||
return mDateTime.date() == QDate::currentDate();
|
||||
}
|
||||
|
||||
bool LDateTime::isFuture() const{
|
||||
return mDateTime > QDateTime::currentDateTime();
|
||||
}
|
||||
|
||||
|
||||
int LDateTime::getDay()const{
|
||||
return mDateTime.date().day();
|
||||
}
|
||||
|
||||
int LDateTime::getWeekDay()const{
|
||||
return mDateTime.date().dayOfWeek();
|
||||
}
|
||||
|
||||
int LDateTime::getMonth()const{
|
||||
return mDateTime.date().month();
|
||||
}
|
||||
|
||||
int LDateTime::getYear()const{
|
||||
return mDateTime.date().year();
|
||||
}
|
||||
|
||||
|
||||
int LDateTime::getSecond()const{
|
||||
return mDateTime.time().second();
|
||||
}
|
||||
|
||||
int LDateTime::getMinute()const{
|
||||
return mDateTime.time().minute();
|
||||
}
|
||||
|
||||
int LDateTime::getHour()const{
|
||||
return mDateTime.time().hour();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
void LDateTime::setDay(const int& data){
|
||||
if(getDay() != data){
|
||||
mDateTime.setDate(QDate(getYear(), getMonth(), data));
|
||||
emit dayChanged();
|
||||
emit dateTimeChanged();
|
||||
}
|
||||
}
|
||||
void LDateTime::setMonth(const int& data){
|
||||
if(getMonth() != data){
|
||||
mDateTime.setDate(QDate(getYear(), data, getDay()));
|
||||
emit monthChanged();
|
||||
emit dateTimeChanged();
|
||||
}
|
||||
}
|
||||
void LDateTime::setYear(const int& data){
|
||||
if(getYear() != data){
|
||||
mDateTime.setDate(QDate(data, getMonth(), getDay()));
|
||||
emit yearChanged();
|
||||
emit dateTimeChanged();
|
||||
}
|
||||
}
|
||||
|
||||
void LDateTime::setSecond(const int& data){
|
||||
if(getSecond() != data){
|
||||
mDateTime.setTime(QTime(getHour(), getMinute(), data));
|
||||
emit secondChanged();
|
||||
emit dateTimeChanged();
|
||||
}
|
||||
}
|
||||
void LDateTime::setMinute(const int& data){
|
||||
if(getMinute() != data){
|
||||
mDateTime.setTime(QTime(getHour(), data, getSecond()));
|
||||
emit minuteChanged();
|
||||
emit dateTimeChanged();
|
||||
}
|
||||
}
|
||||
void LDateTime::setHour(const int& data){
|
||||
if(getHour() != data){
|
||||
mDateTime.setTime(QTime(data, getMinute(), getSecond()));
|
||||
emit hourChanged();
|
||||
emit dateTimeChanged();
|
||||
}
|
||||
}
|
||||
92
linphone-app/src/components/other/date/LDateTime.hpp
Normal file
92
linphone-app/src/components/other/date/LDateTime.hpp
Normal file
|
|
@ -0,0 +1,92 @@
|
|||
/*
|
||||
* Copyright (c) 2010-2022 Belledonne Communications SARL.
|
||||
*
|
||||
* This file is part of linphone-desktop
|
||||
* (see https://www.linphone.org).
|
||||
*
|
||||
* 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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#ifndef DATE_TIME_H_
|
||||
#define DATE_TIME_H_
|
||||
|
||||
// Used to replace QML Date because of Times bugs (local timezones that changes date)
|
||||
|
||||
#include <QObject>
|
||||
#include <QDate>
|
||||
// =============================================================================
|
||||
|
||||
class LDate;
|
||||
class LTime;
|
||||
|
||||
// Note: we don't inherit because we are using a QDateTime and not : QDate and QTime
|
||||
class LDateTime : public QObject {
|
||||
Q_OBJECT
|
||||
public:
|
||||
Q_PROPERTY(int day READ getDay WRITE setDay NOTIFY dayChanged)
|
||||
Q_PROPERTY(int weekday READ getWeekDay NOTIFY dayChanged)
|
||||
Q_PROPERTY(int month READ getMonth WRITE setMonth NOTIFY monthChanged)
|
||||
Q_PROPERTY(int year READ getYear WRITE setYear NOTIFY yearChanged)
|
||||
Q_PROPERTY(int second READ getSecond WRITE setSecond NOTIFY secondChanged)
|
||||
Q_PROPERTY(int minute READ getMinute WRITE setMinute NOTIFY minuteChanged)
|
||||
Q_PROPERTY(int hour READ getHour WRITE setHour NOTIFY hourChanged)
|
||||
Q_PROPERTY(QDateTime dateTime MEMBER mDateTime NOTIFY dateTimeChanged)
|
||||
|
||||
LDateTime (QObject *parent = Q_NULLPTR);
|
||||
LDateTime(const QDateTime& date, QObject *parent = Q_NULLPTR);
|
||||
LDateTime(LDate * date, LTime * time, QObject *parent = Q_NULLPTR);
|
||||
LDateTime(const int& year, const int& month, const int& day, const int& hour, const int& minute, const int& second, QObject *parent = Q_NULLPTR);
|
||||
|
||||
Q_INVOKABLE static LDateTime * create();
|
||||
Q_INVOKABLE static LDateTime * create(LDate * date, LTime * time);
|
||||
Q_INVOKABLE static LDateTime * create(const int& year, const int& month, const int& day, const int& hout, const int& minute, const int& second);
|
||||
|
||||
Q_INVOKABLE QString toDateTimeString(const QString& format = "") const;// Do not use toString as it's a conflict with JS toString()
|
||||
Q_INVOKABLE bool isToday() const;
|
||||
Q_INVOKABLE bool isFuture() const;
|
||||
|
||||
int getDay()const;
|
||||
int getWeekDay()const;
|
||||
int getMonth()const;
|
||||
int getYear()const;
|
||||
|
||||
int getSecond()const;
|
||||
int getMinute()const;
|
||||
int getHour()const;
|
||||
//-------------------------------------
|
||||
void setDay(const int& data);
|
||||
void setMonth(const int& data);
|
||||
void setYear(const int& data);
|
||||
|
||||
void setSecond(const int& data);
|
||||
void setMinute(const int& data);
|
||||
void setHour(const int& data);
|
||||
|
||||
signals:
|
||||
|
||||
void dayChanged();
|
||||
void monthChanged();
|
||||
void yearChanged();
|
||||
|
||||
void secondChanged();
|
||||
void minuteChanged();
|
||||
void hourChanged();
|
||||
|
||||
void dateTimeChanged();
|
||||
|
||||
private:
|
||||
QDateTime mDateTime;
|
||||
};
|
||||
Q_DECLARE_METATYPE(LDateTime*);
|
||||
|
||||
#endif
|
||||
90
linphone-app/src/components/other/date/LTime.cpp
Normal file
90
linphone-app/src/components/other/date/LTime.cpp
Normal file
|
|
@ -0,0 +1,90 @@
|
|||
/*
|
||||
* Copyright (c) 2010-2022 Belledonne Communications SARL.
|
||||
*
|
||||
* This file is part of linphone-desktop
|
||||
* (see https://www.linphone.org).
|
||||
*
|
||||
* 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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "LTime.hpp"
|
||||
|
||||
#include "app/App.hpp"
|
||||
|
||||
#include <QLocale>
|
||||
|
||||
// =============================================================================
|
||||
|
||||
LTime::LTime(QObject *parent) : QObject(parent) {
|
||||
}
|
||||
LTime::LTime(const QTime& time, QObject *parent) : QObject(parent)
|
||||
, mTime(time){
|
||||
}
|
||||
LTime::LTime(const int& hour, const int& minute, const int& second, QObject *parent) : QObject(parent)
|
||||
, mTime(hour, minute, second){
|
||||
}
|
||||
|
||||
LTime * LTime::create(){
|
||||
return new LTime(QTime::currentTime());
|
||||
}
|
||||
|
||||
LTime * LTime::create(const QDateTime& dateTime){
|
||||
return new LTime(dateTime.time());
|
||||
}
|
||||
|
||||
LTime * LTime::create(const int& hour, const int& minute, const int& second){
|
||||
return new LTime(hour, minute, second);
|
||||
}
|
||||
|
||||
QString LTime::toTimeString(const QString& format) const{
|
||||
if(format == "")
|
||||
return QLocale().toString(mTime, QLocale::ShortFormat);
|
||||
else
|
||||
return QLocale().toString(mTime,format);
|
||||
}
|
||||
|
||||
QTime LTime::getTime() const{
|
||||
return mTime;
|
||||
}
|
||||
|
||||
int LTime::getSecond()const{
|
||||
return mTime.second();
|
||||
}
|
||||
|
||||
int LTime::getMinute()const{
|
||||
return mTime.minute();
|
||||
}
|
||||
|
||||
int LTime::getHour()const{
|
||||
return mTime.hour();
|
||||
}
|
||||
|
||||
void LTime::setSecond(const int& data){
|
||||
if(getSecond() != data){
|
||||
mTime = QTime(getHour(), getMinute(), data);
|
||||
emit secondChanged();
|
||||
}
|
||||
}
|
||||
void LTime::setMinute(const int& data){
|
||||
if(getMinute() != data){
|
||||
mTime = QTime(getHour(), data, getSecond());
|
||||
emit minuteChanged();
|
||||
}
|
||||
}
|
||||
void LTime::setHour(const int& data){
|
||||
if(getHour() != data){
|
||||
mTime = QTime(data, getMinute(), getSecond());
|
||||
emit hourChanged();
|
||||
}
|
||||
}
|
||||
66
linphone-app/src/components/other/date/LTime.hpp
Normal file
66
linphone-app/src/components/other/date/LTime.hpp
Normal file
|
|
@ -0,0 +1,66 @@
|
|||
/*
|
||||
* Copyright (c) 2010-2022 Belledonne Communications SARL.
|
||||
*
|
||||
* This file is part of linphone-desktop
|
||||
* (see https://www.linphone.org).
|
||||
*
|
||||
* 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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#ifndef TIME_H_
|
||||
#define TIME_H_
|
||||
|
||||
// Used to replace QML Date because of Times bugs (local timezones that changes date)
|
||||
|
||||
#include <QObject>
|
||||
#include <QTime>
|
||||
// =============================================================================
|
||||
|
||||
class LTime : public QObject {
|
||||
Q_OBJECT
|
||||
public:
|
||||
Q_PROPERTY(int second READ getSecond WRITE setSecond NOTIFY secondChanged)
|
||||
Q_PROPERTY(int minute READ getMinute WRITE setMinute NOTIFY minuteChanged)
|
||||
Q_PROPERTY(int hour READ getHour WRITE setHour NOTIFY hourChanged)
|
||||
|
||||
LTime (QObject *parent = Q_NULLPTR);
|
||||
LTime(const QTime& date, QObject *parent = Q_NULLPTR);
|
||||
LTime(const int& hour, const int& minute, const int& second, QObject *parent = Q_NULLPTR);
|
||||
|
||||
Q_INVOKABLE static LTime* create();
|
||||
Q_INVOKABLE static LTime* create(const QDateTime& dateTime);
|
||||
Q_INVOKABLE static LTime* create(const int& hour, const int& minute, const int& second);
|
||||
|
||||
Q_INVOKABLE QString toTimeString(const QString& format = "") const;// Do not use toString as it's a conflict with JS toString()
|
||||
|
||||
QTime getTime() const;
|
||||
int getSecond()const;
|
||||
int getMinute()const;
|
||||
int getHour()const;
|
||||
|
||||
void setSecond(const int& data);
|
||||
void setMinute(const int& data);
|
||||
void setHour(const int& data);
|
||||
|
||||
signals:
|
||||
|
||||
void secondChanged();
|
||||
void minuteChanged();
|
||||
void hourChanged();
|
||||
|
||||
private:
|
||||
QTime mTime;
|
||||
};
|
||||
Q_DECLARE_METATYPE(LTime*);
|
||||
|
||||
#endif
|
||||
|
|
@ -3,15 +3,20 @@ import QtQuick.Layouts 1.3
|
|||
|
||||
import Common 1.0
|
||||
import Common.Styles 1.0
|
||||
import Linphone 1.0
|
||||
import Units 1.0
|
||||
|
||||
import DateTools 1.0
|
||||
|
||||
import 'qrc:/ui/scripts/Utils/utils.js' as Utils
|
||||
|
||||
Item{
|
||||
id: mainItem
|
||||
property bool allYears : false // if false : years from today
|
||||
property alias selectedDate: monthList.selectedDate
|
||||
property bool hideOldDates : false
|
||||
|
||||
signal clicked(date date);
|
||||
signal clicked(var date);
|
||||
|
||||
RowLayout {
|
||||
id: headerRow
|
||||
|
|
@ -33,7 +38,8 @@ Item{
|
|||
Layout.fillWidth: true
|
||||
Layout.alignment: Qt.AlignCenter
|
||||
horizontalAlignment: Qt.AlignCenter
|
||||
text: new Date(monthList.currentYear, monthList.currentMonth, 1).toLocaleString(Qt.locale(), 'MMMM yyyy')
|
||||
text: DateTools.create(monthList.currentYear, monthList.currentMonth, 1).toDateString('MMMM yyyy')
|
||||
onTextChanged: console.log(monthList.currentYear + "/"+monthList.currentMonth + " => " + text)
|
||||
color: DatePickerStyle.title.color
|
||||
font.pointSize: DatePickerStyle.title.pointSize
|
||||
}
|
||||
|
|
@ -56,28 +62,29 @@ Item{
|
|||
property int maxYears: 5 // Max years to be requested.
|
||||
|
||||
function set(date) {
|
||||
selectedDate = new Date(date)
|
||||
var moveTo = (selectedDate.getFullYear()-minYear) * 12 + selectedDate.getMonth()
|
||||
selectedDate = date
|
||||
var moveTo = (selectedDate.year-minYear) * 12 + (selectedDate.month-1)
|
||||
currentIndex = moveTo
|
||||
}
|
||||
|
||||
property date selectedDate: new Date()
|
||||
property int minYear: mainItem.allYears ? new Date(0,0,0).getFullYear() : new Date().getFullYear()
|
||||
property var selectedDate: DateTools.create()
|
||||
property int minYear: mainItem.allYears ? DateTools.create(0,0,0).year : DateTools.create().year
|
||||
|
||||
snapMode: ListView.SnapOneItem
|
||||
orientation: Qt.Horizontal
|
||||
clip: true
|
||||
|
||||
// One model per month
|
||||
model: (new Date().getFullYear()- minYear + maxYears) * 12
|
||||
model: (DateTools.create().year- minYear + maxYears) * 12
|
||||
|
||||
property int currentYear: Math.floor(currentIndex / 12) + minYear
|
||||
property int currentMonth: currentIndex % 12
|
||||
property int currentMonth: currentIndex % 12 + 1
|
||||
|
||||
highlightFollowsCurrentItem: true
|
||||
highlightRangeMode: ListView.StrictlyEnforceRange
|
||||
highlightMoveDuration: 100
|
||||
|
||||
|
||||
Component.onCompleted: monthList.set(mainItem.selectedDate)
|
||||
|
||||
delegate: Item {
|
||||
|
|
@ -85,8 +92,8 @@ Item{
|
|||
height: monthList.height == 0 ? 100 : monthList.height
|
||||
|
||||
property int year: Math.floor(index / 12) + monthList.minYear
|
||||
property int month: index % 12
|
||||
property int firstDay: new Date(year, month, 1).getDay()
|
||||
property int month: index % 12 + 1
|
||||
property int firstDay: DateTools.create(year, month, 1).weekday % 7
|
||||
|
||||
GridLayout { // 1 month calender
|
||||
id: grid
|
||||
|
|
@ -107,7 +114,9 @@ Item{
|
|||
id: cellItem
|
||||
property int day: index - 7 // 0 = top left below Sunday (-7 to 41)
|
||||
property int date: day - firstDay + 1 // 1-31
|
||||
property bool selected : text.text != '-' && new Date(year, month, date).toDateString() == monthList.selectedDate.toDateString() && text.text && day >= 0
|
||||
property var currentDate: DateTools.create(year, month, date)
|
||||
|
||||
property bool selected : text.text != '-' && currentDate.isEqual(monthList.selectedDate) && text.text && day >= 0
|
||||
width: grid.cellMinSize
|
||||
height: width
|
||||
|
||||
|
|
@ -132,12 +141,12 @@ Item{
|
|||
: cellItem.day < 0
|
||||
? DatePickerStyle.cell.dayHeaderPointSize
|
||||
: DatePickerStyle.cell.dayPointSize
|
||||
font.bold: cellItem.day < 0 || cellItem.selected || new Date(year, month, cellItem.date).toDateString() == new Date().toDateString() // today
|
||||
font.bold: cellItem.day < 0 || cellItem.selected || cellItem.currentDate.isToday()
|
||||
text: {
|
||||
if(cellItem.day < 0)
|
||||
if(cellItem.day < 0){
|
||||
// Magic date to set day names in this order : 'S', 'M', 'T', 'W', 'T', 'F', 'S' in Locale
|
||||
return new Date(1,3,index).toLocaleString(Qt.locale(), 'ddd')[0]
|
||||
else if(new Date(year, month, cellItem.date).getMonth() == month && (!hideOldDates || new Date(year, month, cellItem.date+1) >= new Date())) // new Date use time too
|
||||
return DateTools.create(2000,10,index+1).toDateString("ddd")[0].toUpperCase()
|
||||
}else if(cellItem.currentDate.month == month && (!hideOldDates || cellItem.currentDate.isFuture() || cellItem.currentDate.isToday() )) // new Date use time too
|
||||
return cellItem.date
|
||||
else
|
||||
return '-'
|
||||
|
|
@ -152,7 +161,7 @@ Item{
|
|||
enabled: text.text && text.text != '-' && cellItem.day >= 0
|
||||
|
||||
onClicked: {
|
||||
monthList.selectedDate = new Date(year, month, cellItem.date)
|
||||
monthList.selectedDate = cellItem.currentDate
|
||||
mainItem.clicked(monthList.selectedDate)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,27 +5,31 @@ import Common 1.0
|
|||
import Common.Styles 1.0
|
||||
import Units 1.0
|
||||
|
||||
import TimeTools 1.0
|
||||
|
||||
import 'qrc:/ui/scripts/Utils/utils.js' as Utils
|
||||
|
||||
Item{
|
||||
id: mainItem
|
||||
|
||||
property date selectedTime
|
||||
property var selectedTime: TimeTools.create()
|
||||
property int border: 25
|
||||
|
||||
property int centerPosition: Math.min(height, width)/2
|
||||
property int middleMinSize: centerPosition - border // Minus border
|
||||
|
||||
signal newDate(date date)
|
||||
signal clicked(date date)
|
||||
signal newDate(var date)
|
||||
signal clicked(var date)
|
||||
|
||||
onNewDate: selectedTime = date
|
||||
|
||||
function getDate(hText, mText){
|
||||
var d = new Date()
|
||||
var d = TimeTools.create()
|
||||
if(hText || outer.currentItem)
|
||||
d.setHours(hText ? hText : outer.currentItem.text)
|
||||
d.hour = (hText ? hText : outer.currentItem.text)
|
||||
if(mText || inner.currentItem)
|
||||
d.setMinutes(mText ? mText : inner.currentItem.text)
|
||||
d.setSeconds(0)
|
||||
d.minute = (mText ? mText : inner.currentItem.text)
|
||||
d.second = 0
|
||||
return d;
|
||||
}
|
||||
|
||||
|
|
@ -39,9 +43,9 @@ Item{
|
|||
currentIndex: 0
|
||||
Connections{// startX/Y begin from currentIndex. It must be set to 0 at first.
|
||||
target: mainItem
|
||||
onSelectedTimeChanged: outer.currentIndex = mainItem.selectedTime.getHours() % 24
|
||||
onSelectedTimeChanged: outer.currentIndex = mainItem.selectedTime.hour % 24
|
||||
}
|
||||
Component.onCompleted: currentIndex = mainItem.selectedTime.getHours() % 24
|
||||
Component.onCompleted: currentIndex = mainItem.selectedTime.hour % 24
|
||||
|
||||
highlight: Rectangle {
|
||||
id: rect
|
||||
|
|
@ -100,9 +104,9 @@ Item{
|
|||
currentIndex: 0
|
||||
Connections{// startX/Y begin from currentIndex. It must be set to 0 at first.
|
||||
target: mainItem
|
||||
onSelectedTimeChanged: inner.currentIndex = mainItem.selectedTime.getMinutes() / 5
|
||||
onSelectedTimeChanged: inner.currentIndex = mainItem.selectedTime.minute / 5
|
||||
}
|
||||
Component.onCompleted: currentIndex = mainItem.selectedTime.getMinutes() / 5
|
||||
Component.onCompleted: currentIndex = mainItem.selectedTime.minute / 5
|
||||
|
||||
highlight: Rectangle {
|
||||
width: 30 * 1.5
|
||||
|
|
|
|||
|
|
@ -11,7 +11,9 @@ import Common.Styles 1.0
|
|||
import Units 1.0
|
||||
import UtilsCpp 1.0
|
||||
import ColorsList 1.0
|
||||
|
||||
import DateTools 1.0
|
||||
import TimeTools 1.0
|
||||
import DateTimeTools 1.0
|
||||
import 'qrc:/ui/scripts/Utils/utils.js' as Utils
|
||||
// =============================================================================
|
||||
|
||||
|
|
@ -20,8 +22,8 @@ DialogPlus {
|
|||
property bool isNew: !conferenceInfoModel || conferenceInfoModel.uri === ''
|
||||
property ConferenceInfoModel conferenceInfoModel: ConferenceInfoModel{}
|
||||
onConferenceInfoModelChanged: {
|
||||
dateField.setDate(conferenceManager.conferenceInfoModel.dateTimeUtc);
|
||||
timeField.setTime(conferenceManager.conferenceInfoModel.dateTimeUtc);
|
||||
dateField.setDate(DateTools.create(conferenceManager.conferenceInfoModel.dateTimeUtc));
|
||||
timeField.setTime(TimeTools.create(conferenceManager.conferenceInfoModel.dateTimeUtc));
|
||||
selectedParticipants.setAddresses(conferenceInfoModel)
|
||||
}
|
||||
property bool forceSchedule : false
|
||||
|
|
@ -130,11 +132,11 @@ DialogPlus {
|
|||
}
|
||||
conferenceManager.creationState = 1
|
||||
if( scheduledSwitch.checked){
|
||||
var startDateTime = Utils.buildDate(dateField.getDate(), timeField.getTime())
|
||||
var startDateTime = DateTimeTools.create(dateField.getDate(), timeField.getTime())
|
||||
conferenceInfoModel.isScheduled = true
|
||||
startDateTime.setSeconds(0)
|
||||
startDateTime.second = 0
|
||||
conferenceInfoModel.timeZoneModel = timeZoneField.model.getAt(timeZoneField.currentIndex)
|
||||
conferenceInfoModel.dateTime = startDateTime
|
||||
conferenceInfoModel.dateTime = startDateTime.dateTime
|
||||
conferenceInfoModel.duration = durationField.model[durationField.currentIndex].value
|
||||
}else
|
||||
conferenceInfoModel.isScheduled = false
|
||||
|
|
@ -271,7 +273,7 @@ DialogPlus {
|
|||
Layout.margins: 10
|
||||
columns: 4
|
||||
property var locale: Qt.locale()
|
||||
property date currentDate: new Date()
|
||||
property var currentDate: DateTools.create()
|
||||
property int cellWidth: (parent.width-15-20)/columns
|
||||
|
||||
|
||||
|
|
@ -293,20 +295,22 @@ DialogPlus {
|
|||
Layout.preferredWidth: parent.cellWidth; wrapMode: Text.WordWrap; color: NewConferenceStyle.titles.textColor; font.weight: NewConferenceStyle.titles.weight; font.pointSize: NewConferenceStyle.titles.pointSize }
|
||||
TextField{id: dateField; Layout.preferredWidth: parent.cellWidth
|
||||
color: NewConferenceStyle.fields.textColor; font.weight: NewConferenceStyle.fields.weight; font.pointSize: NewConferenceStyle.fields.pointSize
|
||||
property date currentDate: new Date()
|
||||
property var currentDate: DateTools.create()
|
||||
function getDate(){
|
||||
return currentDate
|
||||
}
|
||||
function setDate(date){
|
||||
console.log(date + " => " +Utils.printObject(date))
|
||||
currentDate = date
|
||||
text = date.toLocaleDateString(scheduleForm.locale, Qt.ISODate)
|
||||
text = date.toDateString()
|
||||
}
|
||||
text: conferenceManager.conferenceInfoModel ? conferenceManager.conferenceInfoModel.dateTime.toLocaleDateString(scheduleForm.locale, Qt.ISODate) : ''
|
||||
text: conferenceManager.conferenceInfoModel && conferenceManager.conferenceInfoModel.isScheduled ? conferenceManager.conferenceInfoModel.dateTime.toLocaleDateString(scheduleForm.locale, Qt.ISODate) : DateTools.create().toDateString()
|
||||
|
||||
icon: 'drop_down_custom'
|
||||
MouseArea{
|
||||
anchors.fill: parent
|
||||
onClicked: {
|
||||
window.attachVirtualWindow(Utils.buildCommonDialogUri('DateTimeDialog'), {hideOldDates:true, showDatePicker:true, selectedDate: new Date(dateField.getDate())}
|
||||
window.attachVirtualWindow(Utils.buildCommonDialogUri('DateTimeDialog'), {hideOldDates:true, showDatePicker:true, selectedDate: dateField.getDate()}
|
||||
, function (status) {
|
||||
if(status){
|
||||
dateField.setDate(status.selectedDate)
|
||||
|
|
@ -318,16 +322,16 @@ DialogPlus {
|
|||
}
|
||||
TextField{id: timeField; Layout.preferredWidth: parent.cellWidth
|
||||
color: NewConferenceStyle.fields.textColor; font.weight: NewConferenceStyle.fields.weight; font.pointSize: NewConferenceStyle.fields.pointSize
|
||||
property var currentTime: TimeTools.create()
|
||||
function getTime(){
|
||||
return Date.fromLocaleTimeString(scheduleForm.locale, timeField._text, 'hh:mm')
|
||||
return currentTime
|
||||
}
|
||||
function setTime(date){
|
||||
_text = date.toLocaleTimeString(scheduleForm.locale, 'hh:mm')
|
||||
text = UtilsCpp.toTimeString(date, 'hh:mm')// Display the unchanged time
|
||||
function setTime(time){
|
||||
currentTime = time
|
||||
text = time.toTimeString('hh:mm')
|
||||
}
|
||||
// hidden time to be used from JS : JS Local time can be wrong on Windows because of daylights that are not takken account.
|
||||
property string _text: conferenceManager.conferenceInfoModel? conferenceManager.conferenceInfoModel.dateTime.toLocaleTimeString(scheduleForm.locale, 'hh:mm') : ''
|
||||
text: conferenceManager.conferenceInfoModel? UtilsCpp.toTimeString(conferenceManager.conferenceInfoModel.dateTimeUtc, 'hh:mm') : ''
|
||||
|
||||
text: conferenceManager.conferenceInfoModel && conferenceManager.conferenceInfoModel.isScheduled ? UtilsCpp.toTimeString(conferenceManager.conferenceInfoModel.dateTimeUtc, 'hh:mm') : TimeTools.create().toTimeString('hh:mm')
|
||||
|
||||
icon: 'drop_down_custom'
|
||||
onEditingFinished: if(rightStackView.currentItemType === 2) {
|
||||
|
|
@ -341,7 +345,7 @@ DialogPlus {
|
|||
anchors.right: parent.right
|
||||
width: parent.width-50
|
||||
onClicked: {
|
||||
window.attachVirtualWindow(Utils.buildCommonDialogUri('DateTimeDialog'), {showTimePicker:true, selectedTime: new Date(timeField.getTime())}
|
||||
window.attachVirtualWindow(Utils.buildCommonDialogUri('DateTimeDialog'), {showTimePicker:true, selectedTime: timeField.getTime()}
|
||||
, function (status) {
|
||||
if(status){
|
||||
timeField.setTime(status.selectedTime)
|
||||
|
|
@ -374,31 +378,6 @@ DialogPlus {
|
|||
selectionWidth: 500
|
||||
rootItem: conferenceManager
|
||||
}
|
||||
|
||||
function updateDateTime(){
|
||||
var storedDate
|
||||
if( dateField.text != '' && timeField.text != ''){
|
||||
storedDate = Utils.buildDate(dateField.getDate(), timeField.getTime() )
|
||||
}else
|
||||
storedDate = new Date()
|
||||
var currentDate = new Date()
|
||||
if(currentDate >= storedDate){
|
||||
var nextStoredDate = UtilsCpp.addMinutes(new Date(), 1)
|
||||
dateField.setDate(nextStoredDate)
|
||||
timeField.setTime(nextStoredDate)
|
||||
if(rightStackView.currentItemType === 2) rightStackView.currentItem.selectedTime = nextStoredDate
|
||||
}
|
||||
}
|
||||
Timer{
|
||||
running: scheduleForm.visible && conferenceManager.isNew
|
||||
repeat: true
|
||||
interval: 1000
|
||||
triggeredOnStart: true
|
||||
onTriggered: {
|
||||
if(conferenceManager.isNew)
|
||||
scheduleForm.updateDateTime()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ColumnLayout {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue