예제 #1
0
void KOEditorGeneralTodo::dateChanged()
{
    KLocale *l = KGlobal::locale();
    QString dateTimeStr = "";

    if(mStartCheck->isChecked())
    {
        dateTimeStr += i18n("Start: %1").arg(
                           l->formatDate(mStartDateEdit->date()));
        if(mTimeButton->isChecked())
            dateTimeStr += QString(" %1").arg(
                               l->formatTime(mStartTimeEdit->getTime()));
    }

    if(mDueCheck->isChecked())
    {
        dateTimeStr += i18n("   Due: %1").arg(
                           l->formatDate(mDueDateEdit->date()));
        if(mTimeButton->isChecked())
            dateTimeStr += QString(" %1").arg(
                               l->formatTime(mDueTimeEdit->getTime()));
    }

    emit dateTimeStrChanged(dateTimeStr);
    QDateTime endDt(mDueDateEdit->date(), mDueTimeEdit->getTime());
    emit signalDateTimeChanged(endDt, endDt);
}
예제 #2
0
/******************************************************************************
*  Return the alarm time text in the form "date time".
*/
QString AlarmListViewItem::alarmTimeText(const DateTime &dateTime) const
{
    KLocale *locale = KGlobal::locale();
    QString dateTimeText = locale->formatDate(dateTime.date(), true);
    if(!dateTime.isDateOnly())
    {
        dateTimeText += ' ';
        QString time = locale->formatTime(dateTime.time());
        if(mTimeHourPos == -2)
        {
            // Initialise the position of the hour within the time string, if leading
            // zeroes are omitted, so that displayed times can be aligned with each other.
            mTimeHourPos = -1;     // default = alignment isn't possible/sensible
            if(!QApplication::reverseLayout())     // don't try to align right-to-left languages
            {
                QString fmt = locale->timeFormat();
                int i = fmt.find(QRegExp("%[kl]"));   // check if leading zeroes are omitted
                if(i >= 0  &&  i == fmt.find('%'))    // and whether the hour is first
                    mTimeHourPos = i;             // yes, so need to align
            }
        }
        if(mTimeHourPos >= 0  && (int)time.length() > mTimeHourPos + 1
                &&  time[mTimeHourPos].isDigit()  &&  !time[mTimeHourPos + 1].isDigit())
            dateTimeText += '~';     // improve alignment of times with no leading zeroes
        dateTimeText += time;
    }
    return dateTimeText + ' ';
}
예제 #3
0
	QString DurationToString(Uint32 nsecs)
	{
		KLocale* loc = KGlobal::locale();
		QTime t;
		int ndays = nsecs / 86400;
		t = t.addSecs(nsecs % 86400);
		QString s = loc->formatTime(t,true,true);
		if (ndays > 0)
			s = i18n("1 day ","%n days ",ndays) + s;

		return s;
	}
예제 #4
0
QString DateFormatter::fancy( time_t t ) const
{
  KLocale *locale = KGlobal::locale();

  if ( t <= 0 ) {
    return i18nc( "invalid time specified", "unknown" );
  }

  if ( mTodayOneSecondBeforeMidnight < time( 0 ) ) {
    // determine time_t value of today 23:59:59
    const QDateTime today( QDate::currentDate(), QTime( 23, 59, 59 ) );
    mTodayOneSecondBeforeMidnight = today.toTime_t();
  }

  QDateTime old;
  old.setTime_t( t );

  if ( mTodayOneSecondBeforeMidnight >= t ) {
    const time_t diff = mTodayOneSecondBeforeMidnight - t;
    if ( diff < 7 * 24 * 60 * 60 ) {
      if ( diff < 24 * 60 * 60 ) {
        return i18n( "Today %1",
                     locale->formatTime( old.time(), true ) );
      }
      if ( diff < 2 * 24 * 60 * 60 ) {
        return i18n( "Yesterday %1",
                     locale->formatTime( old.time(), true ) );
      }
      for ( int i = 3; i < 8; i++ ) {
        if ( diff < i * 24 * 60 * 60 ) {
          return i18nc( "1. weekday, 2. time", "%1 %2" ,
                        locale->calendar()->weekDayName( old.date() ) ,
                        locale->formatTime( old.time(), true ) );
        }
      }
    }
  }

  return locale->formatDateTime( old );
}
예제 #5
0
/**
 * Deal with right click's
 */
void KBinaryClock::openContextMenu() {
		bool bImmutable = config()->isImmutable();

		KPopupMenu *menu = new KPopupMenu();
		menu->insertTitle( SmallIcon( "clock" ), i18n( "KBinaryClock" ) );

		KLocale *loc = KGlobal::locale();
		QDateTime dt = QDateTime::currentDateTime();

		KPopupMenu *copyMenu = new KPopupMenu( menu );
		copyMenu->insertItem(loc->formatDateTime(dt), 201);
		copyMenu->insertItem(loc->formatDate(dt.date()), 202);
		copyMenu->insertItem(loc->formatDate(dt.date(), true), 203);
		copyMenu->insertItem(loc->formatTime(dt.time()), 204);
		copyMenu->insertItem(loc->formatTime(dt.time(), true), 205);
		copyMenu->insertItem(dt.date().toString(), 206);
		copyMenu->insertItem(dt.time().toString(), 207);
		copyMenu->insertItem(dt.toString(), 208);
		connect( copyMenu, SIGNAL( activated(int) ), this, SLOT( slotCopyMenuActivated(int) ) );

		if (!bImmutable)
		{
				if (kapp->authorize("user/root"))
				{
						menu->insertItem(SmallIcon("date"), i18n("&Adjust Date && Time..."), 103, 4);
				}
				menu->insertItem(SmallIcon("kcontrol"), i18n("Date && Time &Format..."), 104, 5);
		}

		menu->insertItem(SmallIcon("editcopy"), i18n("C&opy to Clipboard"), copyMenu, 105, 6);
		if (!bImmutable)
		{
				menu->insertSeparator(7);
				menu->insertItem(SmallIcon("configure"), i18n("&Configure KBinaryClock..."), 102, 8);
		}
		int result = menu->exec( QCursor::pos() );

		KProcess proc;
		switch (result) {
	case 102:
		preferences();
		break;
	case 103:
		proc << locate("exe", "kdesu");
		proc << "--nonewdcop";
		proc << QString("%1 clock --lang %2")
				.arg(locate("exe", "kcmshell"))
				.arg(KGlobal::locale()->language());
		proc.start(KProcess::DontCare);
		break;
	case 104:
		proc << locate("exe", "kcmshell");
		proc << "language";
					proc.start(KProcess::DontCare);
		break;
	case 110:
		preferences();
		break;
		} /* switch() */
		delete menu;
}