[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-core-devel
Subject:    Re: [PATCH] make ksnapshot increment the last number
From:       Riccardo Iaconelli <riccardo () kde ! org>
Date:       2007-10-03 15:50:07
Message-ID: 200710031750.08659.riccardo () kde ! org
[Download RAW message or body]

On Wednesday 03 October 2007 11:10:28 Jos Poortvliet wrote:
> On 10/3/07, Riccardo Iaconelli <riccardo@kde.org> wrote:
> > On Wednesday 03 October 2007 08:25:49 Andras Mantia wrote:
> > > On Tuesday 02 October 2007, Matthew Woehlke wrote:
> > > > Hmm... for writing maybe. But DD-MM-YYYY doesn't sort properly, where
> > > > YYYY-MM-DD does ;-).
> > >
> > > And that is official for some countries, like Hungary. :)
> >
> > Shall we check for where the 20?? sequence appears, and increment
> > smartly?
>
> Well, if you're up to doing that, I think it would rock. But as 4.0 is
> getting closer, we might just fix it basically (just increment the
> last number) and get back to this for 4.1? Unless you  or someone else
> can whip up a patch in 20 minutes ;-)

As you asked for it, I did it. =)

The behiavour now is the following:
- KSnapshot checks if there are any numbers in the filename.
- If there is any number, it checks for an xx-xx-20xx sequence.
   - If this sequence is found, it assumes the user is saving using the 
dd-mm-yyyy sequence, and increments the day.
   - If it's not, it just increments the last number, as it has been corrected 
in the previous patch.

I choosed to support dd-mm-yyyy instead of mm-dd-yyyy as for what I saw it's a 
sequence way more used in the world (at least outside the USA).

Please revise the patch as I'm not a regexp wizard, and please double check as 
I couldn't test the modifications because my ksnapshot (for an unknown 
reason) crashes when trying to open the filedialog to save the
screenshot... =\
For now I implemented just the above scenario, please tell me if you have 
others in mind.
Tell me if it's ok to commit, and I'll do that immediately!

Bye,
-Riccardo
-- 
GPG key:
3D0F6376
When encrypting, please encrypt also for this subkey:
9EBD7FE1
-----
Pace Peace Paix Paz Frieden Pax Pokój Friður Fred Béke 和平
Hasiti Lapé Hetep Malu Mир Wolakota Santiphap Irini Peoch
Shanti Vrede Baris Rój Mír Taika Rongo Sulh Mir Py'guapy 평화

["ksnapshot-insanity-check.diff" (text/x-diff)]

Index: ksnapshot/ksnapshotobject.cpp
===================================================================
--- ksnapshot/ksnapshotobject.cpp	(revisione 719927)
+++ ksnapshot/ksnapshotobject.cpp	(copia locale)
@@ -50,20 +50,32 @@
 void KSnapshotObject::autoincFilename()
 {
     // Extract the filename from the path
-    QString name= filename.fileName();
+    QString name = filename.fileName();
 
     // If the name contains a number then increment it
     QRegExp numSearch("[0-9]+");
 
     // Does it have a number?
-    int start = numSearch.indexIn(name);
+    int start = numSearch.lastIndexIn(name);
     if (start != -1) {
-        // It has a number, increment it
-        int len = numSearch.matchedLength();
-        QString numAsStr= name.mid(start, len);
-        QString number = QString::number(numAsStr.toInt() + 1);
-        number = number.rightJustified( len, '0');
-        name.replace(start, len, number );
+        // Let's try to guess if the user is using the insane dd-mm-yyyy date format
+        QRegExp ddmmyyyyDate("\\d\\d-\\d\\d-20\\d\\d");
+        int insaneStandard = ddmmyyyyDate.lastIndexIn(name);
+        if (insaneStandard != -1) {
+            // The user seems to be using the insane way to write dates. We would \
love to, but +            // unfortunately we can't change that. We haven't conquered \
the world (yet). Let's try to be smart at least! +            QString numAsStr = \
name.mid(insaneStandard, 2); //get the first two digits (day) +            QString \
number = QString::number(numAsStr.toInt() + 1); +            number = \
number.rightJustified(2, '0'); +            name.replace(insaneStandard, 2, number);
+        } else {
+            // It has just a generic number, increment it
+            int len = numSearch.matchedLength();
+            QString numAsStr= name.mid(start, len);
+            QString number = QString::number(numAsStr.toInt() + 1);
+            number = number.rightJustified(len, '0');
+            name.replace(start, len, number);
+        }
     }
     else {
         // no number
Index: ksnapshot/kbackgroundsnapshot.cpp
===================================================================
--- ksnapshot/kbackgroundsnapshot.cpp	(revisione 719927)
+++ ksnapshot/kbackgroundsnapshot.cpp	(copia locale)
@@ -90,7 +90,7 @@
 
 void KBackgroundSnapshot::savePictureOnDesktop()
 {
-    filename = KUrl( KGlobalSettings::desktopPath()+i18n("snapshot")+"1.png" );
+    filename = KUrl( KGlobalSettings::desktopPath()+i18n("snapshot")+"01.png" );
     // Make sure the name is not already being used
     while(KIO::NetAccess::exists( filename, KIO::NetAccess::DestinationSide, 0L )) {
         autoincFilename();
Index: ksnapshot/ksnapshot.cpp
===================================================================
--- ksnapshot/ksnapshot.cpp	(revisione 719927)
+++ ksnapshot/ksnapshot.cpp	(copia locale)
@@ -152,7 +152,7 @@
     setDelay( conf.readEntry("delay", 0) );
     setMode( conf.readEntry("mode", 0) );
     setIncludeDecorations(conf.readEntry("includeDecorations",true));
-    filename = KUrl( conf.readPathEntry( "filename", \
QDir::currentPath()+'/'+i18n("snapshot")+"1.png" )); +    filename = KUrl( \
conf.readPathEntry( "filename", QDir::currentPath()+'/'+i18n("snapshot")+"01.png" )); \
  // Make sure the name is not already being used
     while(KIO::NetAccess::exists( filename, KIO::NetAccess::DestinationSide, this )) \
{



[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic