QString formatTime(time_t t) { KLocale *l = KGlobal::locale(); if ( l ) { return l->formatDateTime( QDateTime::fromTime_t(t) ); } return QDateTime::fromTime_t(t).toString(); }
QString DateFormatter::localized( time_t t, bool shortFormat, bool includeSecs, const QString &lang ) const { QDateTime tmp; QString ret; KLocale *locale = KGlobal::locale(); tmp.setTime_t( t ); if ( !lang.isEmpty() ) { locale = new KLocale( lang, lang, lang ); ret = locale->formatDateTime( tmp, ( shortFormat ? KLocale::ShortDate : KLocale::LongDate ), includeSecs ); delete locale; } else { ret = locale->formatDateTime( tmp, ( shortFormat ? KLocale::ShortDate : KLocale::LongDate ), includeSecs ); } return ret; }
QVariant DocumentModel::data(const QModelIndex &idx, int role) const { if(role == Qt::DisplayRole) { if(idx.column() == Document_LastModified ) { KLocale *locale = KGlobal::locale(); QDateTime date = QSqlQueryModel::data(idx, role).toDateTime(); return locale->formatDateTime( date, KLocale::ShortDate ); } else if( idx.column() == Document_CreationDate ) { KLocale *locale = KGlobal::locale(); QDate date = QSqlQueryModel::data( idx, role ).toDate(); return locale->formatDate( date, KLocale::ShortDate ); } else if(idx.column() == Document_ClientId ) { const QString uid = QSqlQueryModel::data( idx, role ).toString(); return uid; } else if( idx.column() == Document_ClientName ) { QModelIndex uidIdx = idx.sibling( idx.row(), Document_ClientId ); const QString uid = QSqlQueryModel::data( uidIdx, role ).toString(); // kDebug() << "Checking for UID " << uid; if( uid.isEmpty() ) return ""; if( mAddresses.contains( uid ) ) { if( mAddresses.value(uid).isEmpty() ) { // empty address means that there is no valid entry in this addressbook return i18n("not found"); } const QString realName = mAddresses.value(uid).realName(); // kDebug() << "returning " << realName; return realName; } else { mAddressProvider->getAddressee( uid ); } return i18n("retrieving..."); } } else if( role == RawTypes ) { if(idx.column() == Document_LastModified ) { return QSqlQueryModel::data( idx, Qt::DisplayRole ).toDateTime(); } else if( idx.column() == Document_CreationDate ) { return QSqlQueryModel::data( idx, Qt::DisplayRole ).toDate(); } } else if( role == Qt::SizeHintRole ) { QFont f = QSqlQueryModel::data(idx, Qt::FontRole ).value<QFont>(); QFontMetrics fm(f); int h = fm.height(); return QSize( 0, h + 4 ); } return QSqlQueryModel::data(idx, role); }
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 ); }
void KrecipesView::actionRecipe( int recipeID, int action ) { //FIXME: Don't use magic numbers, use enums instead switch ( action ) { case 0: //Show { showRecipe( recipeID ); break; } case 1: // Edit { if ( !inputPanel->everythingSaved() ) { switch ( KMessageBox::questionYesNoCancel( this, i18n( "A recipe contains unsaved changes.\n" "Do you want to save changes made to this recipe before editing another recipe?" ), i18n( "Unsaved changes" ) ) ) { case KMessageBox::Yes: inputPanel->save(); break; case KMessageBox::No: break; case KMessageBox::Cancel: return ; } } inputPanel->loadRecipe( recipeID ); slotSetPanel( RecipeEdit ); break; } case 2: //Remove (not used at the moment) { switch ( KMessageBox::questionYesNo( this, i18n( "Are you sure you want to permanently remove the recipe, %1?" ,database->recipeTitle(recipeID)), i18n( "Confirm remove" ) ) ) { case KMessageBox::Yes: database->removeRecipe( recipeID ); break; case KMessageBox::No: break; } QWidget * vis_panel = rightPanel->visiblePanel(); if ( vis_panel == selectPanel ) selectPanel->getActionsHandler()->selectionChangedSlot(); break; } case 3: //Add to shopping list { shoppingListPanel->addRecipeToShoppingList( recipeID ); break; } case 4: //Show text in status bar { Recipe r; database->loadRecipe(&r,RecipeDB::Meta|RecipeDB::Noatime,recipeID ); KLocale *locale = KGlobal::locale(); QString statusText = QString("<b>%1</b> %2 <b>%3</b> %4 <b>%5</b> %6") .arg(i18nc("Recipe created", "Created:")).arg(locale->formatDateTime(r.ctime)) .arg(i18nc("Recipe modified", "Modified:")).arg(locale->formatDateTime(r.mtime)) .arg(i18nc("Recipe last accessed", "Last Accessed:")).arg(locale->formatDateTime(r.atime)); emit signalChangeStatusbar( statusText ); break; } case 5: //Clear text in status bar { emit signalChangeStatusbar( QString("") ); break; } } }
/** * 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; }