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

List:       kde-commits
Subject:    KDE/kdebindings/perl/qtgui/examples/tutorial/addressbook
From:       Chris Michael Burel <chrisburel () gmail ! com>
Date:       2010-10-15 20:51:51
Message-ID: 20101015205151.32E56AC896 () svn ! kde ! org
[Download RAW message or body]

SVN commit 1186331 by burel:

Finish tutorial/addressbook example.


 M  +8 -3      part3/AddressBook.pm  
 M  +19 -5     part4/AddressBook.pm  
 M  +21 -6     part5/AddressBook.pm  
 A             part6 (directory)  
 A             part6/AddressBook.pm  
 A             part6/FindDialog.pm  
 AM            part6/part6.pl  
 A             part7 (directory)  
 A             part7/AddressBook.pm  
 A             part7/FindDialog.pm  
 AM            part7/part7.pl  


--- trunk/KDE/kdebindings/perl/qtgui/examples/tutorial/addressbook/part3/AddressBook.pm #1186330:1186331
@@ -104,10 +104,15 @@
             this->tr('Please enter a name and address.'));
     }
 
-    if (!defined this->{contacts}->{$name}) {
+    if (!exists this->{contacts}->{$name}) {
+        my $order = this->{order};
+        ++$order if grep { this->{contacts}->{$_}->{order} == $order } keys %{this->{contacts}};
+        my @toInc = grep { this->{contacts}->{$_}->{order} >= $order } keys %{this->{contacts}};
+        map{ this->{contacts}->{$_}->{order}++ } @toInc;
         this->{contacts}->{$name}->{address} = $address;
-        this->{contacts}->{$name}->{order} = this->{order};
-        ++this->{order};
+        this->{contacts}->{$name}->{order} = $order;
+
+        this->{order} = $order + 1;
         Qt::MessageBox::information(this, this->tr('Add Successful'),
             sprintf this->tr('\'%s\' has been added to your address book.'), $name);
     } else {
--- trunk/KDE/kdebindings/perl/qtgui/examples/tutorial/addressbook/part4/AddressBook.pm #1186330:1186331
@@ -125,11 +125,16 @@
 # [submitContact() function part1]
     if (this->{currentMode} == AddingMode) {
         
-        if (!defined this->{contacts}->{$name}) {
+        if (!exists this->{contacts}->{$name}) {
+            my $order = this->{order};
+            ++$order if grep { this->{contacts}->{$_}->{order} == $order } keys %{this->{contacts}};
+            my @toInc = grep { this->{contacts}->{$_}->{order} >= $order } keys %{this->{contacts}};
+            map{ this->{contacts}->{$_}->{order}++ } @toInc;
             this->{contacts}->{$name}->{address} = $address;
-            this->{contacts}->{$name}->{order} = this->{order};
-            this->{order}++;
+            this->{contacts}->{$name}->{order} = $order;
 
+            this->{order} = $order + 1;
+
             Qt::MessageBox::information(this, this->tr('Add Successful'),
                 sprintf this->tr('\'%s\' has been added to your address book.'), $name);
         } else {
@@ -141,7 +146,7 @@
     } elsif (this->{currentMode} == EditingMode) {
         
         if (this->{oldName} ne $name) {
-            if (!defined this->{contacts}->{$name}) {
+            if (!exists this->{contacts}->{$name}) {
                 Qt::MessageBox::information(this, this->tr('Edit Successful'),
                     sprintf this->tr('\'%s\' has been edited in your address book.'), this->{oldName});
                 this->{contacts}->{$name}->{address} = $address;
@@ -172,7 +177,7 @@
     my $name = this->{nameLine}->text();
     my $address = this->{addressText}->toPlainText();
 
-    if (defined this->{contacts}->{$name}) {
+    if (exists this->{contacts}->{$name}) {
 
         my $button = Qt::MessageBox::question(this,
             this->tr('Confirm Remove'),
@@ -182,7 +187,16 @@
         if ($button == Qt::MessageBox::Yes()) {
             
             this->previous();
+            my $order = this->{contacts}->{$name}->{order};
             delete this->{contacts}->{$name};
+            my @toDec = grep { this->{contacts}->{$_}->{order} >= $order } keys %{this->{contacts}};
+            map{ this->{contacts}->{$_}->{order}-- } @toDec;
+            if ( this->{order} == 0 ) {
+                this->{order} = scalar keys %{this->{contacts}} - 1;
+            }
+            else {
+                --(this->{order});
+            };
 
             Qt::MessageBox::information(this, this->tr('Remove Successful'),
                 sprintf this->tr('\'%s\' has been removed from your address book.'), $name);
--- trunk/KDE/kdebindings/perl/qtgui/examples/tutorial/addressbook/part5/AddressBook.pm #1186330:1186331
@@ -129,11 +129,17 @@
     }
     if (this->{currentMode} == AddingMode) {
         
-        if (!defined this->{contacts}->{$name}) {
+        if (!exists this->{contacts}->{$name}) {
+            my $order = this->{order};
+            ++$order if grep { this->{contacts}->{$_}->{order} == $order } keys %{this->{contacts}};
+            my @toInc = grep { this->{contacts}->{$_}->{order} >= $order } keys %{this->{contacts}};
+            map{ this->{contacts}->{$_}->{order}++ } @toInc;
+
             this->{contacts}->{$name}->{address} = $address;
-            this->{contacts}->{$name}->{order} = this->{order};
-            this->{order}++;
+            this->{contacts}->{$name}->{order} = $order;
 
+            this->{order} = $order + 1;
+
             Qt::MessageBox::information(this, this->tr('Add Successful'),
                 sprintf this->tr('\'%s\' has been added to your address book.'), $name);
         } else {
@@ -143,7 +149,7 @@
     } elsif (this->{currentMode} == EditingMode) {
         
         if (this->{oldName} ne $name) {
-            if (!defined this->{contacts}->{$name}) {
+            if (!exists this->{contacts}->{$name}) {
                 Qt::MessageBox::information(this, this->tr('Edit Successful'),
                     sprintf this->tr('\'%s\' has been edited in your address book.'), this->{oldName});
                 this->{contacts}->{$name}->{address} = $address;
@@ -172,7 +178,7 @@
     my $name = this->{nameLine}->text();
     my $address = this->{addressText}->toPlainText();
 
-    if (defined this->{contacts}->{$name}) {
+    if (exists this->{contacts}->{$name}) {
 
         my $button = Qt::MessageBox::question(this,
             this->tr('Confirm Remove'),
@@ -182,7 +188,16 @@
         if ($button == Qt::MessageBox::Yes()) {
             
             this->previous();
+            my $order = this->{contacts}->{$name}->{order};
             delete this->{contacts}->{$name};
+            my @toDec = grep { this->{contacts}->{$_}->{order} >= $order } keys %{this->{contacts}};
+            map{ this->{contacts}->{$_}->{order}-- } @toDec;
+            if ( this->{order} == 0 ) {
+                this->{order} = scalar keys %{this->{contacts}} - 1;
+            }
+            else {
+                --(this->{order});
+            }
 
             Qt::MessageBox::information(this, this->tr('Remove Successful'),
                 sprintf this->tr('\'%s\' has been removed from your address book.'), $name);
@@ -233,7 +248,7 @@
     if (this->{dialog}->exec() == Qt::Dialog::Accepted()) {
         my $contactName = this->{dialog}->getFindText();
 
-        if (defined this->{contacts}->{$contactName}) {
+        if (exists this->{contacts}->{$contactName}) {
             this->{nameLine}->setText($contactName);
             this->{addressText}->setText(this->{contacts}->{$contactName}->{address});
         } else {
[prev in list] [next in list] [prev in thread] [next in thread] 

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